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:
I recently had a reason to code a process to deactivate a record to a custom statuscode and that following method can also be used.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient.updatestateandstatusforentity?view=dynamics-xrmtooling-ce-9