MSCRM: Setting Status / State on an Activity
In a recent (heavily customised) implementation of MSCRM for a call centre I have had the requirement to set the state of a Phonecall Activity to "Completed", depending certain actions by the user on the frontend.
MSCRM exposes itself via the "CrmWebservice"- and "MetadataService" web services. All the CRM entities, like Contact, Incident, etc. are extensions of the BusinessEntity base class, and so it is also for Activity, from which Phonecall derives.
Ussually when updating any BusinessEntity, I used the CrmService.Update(BusinessEntity) webmethod. This, however, does not work for updating the state (or status) on any type of activity - to do this you need to use the CrmService.Execute(CrmService.Request) webmethod, which returns a CrmService.Response.
This might seem unintuitive at first, though it is quite easy to use, as there are pre-defined classes deriving from Request and Response - one of these are SetStatePhoneCallRequest.
The state on a phonecall is updated as follows:
private void CloseCall(Guid callId)
{
using (CrmService svc =
ServiceFactory.GetWebService<CrmService>())
{
SetStatePhoneCallRequest request = new SetStatePhoneCallRequest();
request.EntityId = callId;
request.PhoneCallState
= PhoneCallState.Completed;
request.PhoneCallStatus = 2;
svc.Execute(request);
}
}
Examining the SetStatePhoneCallResponse being returned by Execute is not necessary, as it has no public fields. I am unsure why this specific property on a Phonecall can not be set using the Update webmethod (which works for all the other properties of a phonecall), however this is the correct way to do update status on *any* type of activity. (Note for example the SetStateQuoteRequest, SetStatePriceLevelRequest, etc. classes).