Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

Posts Tagged ‘Close Service Activity on Create’

Close Service Activity On Create Message In PlugIn

Posted by Ali Khan on February 19, 2010

Here is a simple code to close the service activity in a MS CRM Plugin.

  1: SetStateServiceAppointmentRequest req = new SetStateServiceAppointmentRequest();
  2: req.ServiceAppointmentState = ServiceAppointmentState.Closed;
  3: req.ServiceAppointmentStatus = 8;
  4: req.EntityId = new Guid(context.OutputParameters["id"].ToString());
  5: SetStateServiceAppointmentResponse resp = (SetStateServiceAppointmentResponse)crmService.Execute(req);

But the above code will work perfectly only if the message is Post Update but doesn’t work if the message is Post Create means it doesn’t close the service activity. Strangely, it doesn’t give any error as well. To add to my surprise, if you had configure any plugin on “SetState” or “SetStateDynamic” for serviceappointment even those plugin will be trigger, but the state of the service activity will not change. Why?, i am not sure.

But does this means we cannot close service activity on the “Create” message?, well the trick is to register the above plug-in as Asynchronous mode (as shown below). now the above message will Close the Service Activity even on the Create Message.

image

Advertisements

Posted in MS CRM 4.0, MS CRM Plugin | Tagged: | 2 Comments »