Automatically Set The Site In The Service Activity Form

Cold Day In Hell...

I've been doing quite a bit of work with Service Scheduling lately, and one of the requirements was to automatically populate the "Site" lookup field on the "Service Activity" form with the default site of the User. Because I needed to fill in this field when I first create a Service Activity, the only choice I had was to write some JScript code which ran in the form's OnLoad event and performed the following steps:

  1. Call the CRM web service and get the current user's ID, executing the WhoAmI Message.
  2. Call the CRM web service and get the default site of the user (if any), executing the Retrieve Message and passing the TargetRetrieveSystemUser Class.
  3. Set the Site lookup field on the Service Activity form.

If you have tried accessing web services in JScript, you know how time consuming and error prone this can be since you have to construct the SOAP request messages manually. In addition, it is not always obvious what the contents of the request or response messages should actually look like for a particular web service. The easiest way to figure this out is to actually build a simple .NET application that calls the same web service calls, and capture HTTP requests that get sent between the browser and server using the Fiddler tool.

Rather than boring you with pages of JScript code, I've attached a copy of my script here. All you need to do is copy and paste this into the OnLoad event of the Service Activity entity form, and away you go. I've included some error handling to make sure the script degrades gracefully in the event of an error.

This posting is provided "AS IS" with no warranties, and confers no rights.

Laughing Boy

ServiceActivity_OnLoad.zip