Prior to Microsoft Dynamics CRM 2015 (update 1) we had to use special messages when updating special fields. Those special fields include the record’s status (statecode, statuscode), the owner of the record (ownerid), etc. The full list of those special messages can be found on msdn, here.

Now since those special messages are deprecated we can now (and should) utilize the regular update statement.

Instead of (deprecated, do not use!):

service.Execute(new SetStateRequest
{
EntityMoniker = new EntityReference("contact", new Guid("...")),
State = new OptionSetValue(1), //Status
Status = new OptionSetValue(2) //Status reason
});

We can now simply use:

Entity party = new Entity("contact", new Guid("..."));
party["statecode"] = new OptionSetValue(1); //Status
party["statuscode"] = new OptionSetValue(2); //Status reason
service.Update(party);

Much better!

Just make sure the combination of status reason (statuscode) and status (statecode) is a valid combination or it will throw an exception. You can verify the configured combinations (and their optionset value) in your solution when navigation to the statuscode field:

StatusReason_Status_Combination
Example status & status reason combinations

One thought on “Update status (statecode & statuscode) of a CRM record using C#”

Leave a Reply