Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

|

How to programmatically set the status code field of a Dynamic entity

Post Author: Joe D365 |

If you are working on creating or updating a dynamic entity in Microsoft Dynamics CRM and got stuck on properly setting the statuscode field please read further:

Assigning value to the statuscode fields is not same as assigning any other fields programmatically. It needs a bit of trick. Statecode and statucode fields in CRM are tightly related and they go hand on hand.

Let us consider a setting like this:

Statuscodename Statuscode
Open 1
Done 2
Canceled 3
Scheduled 4
statecodename Statuscode
Open 0
Completed 1
Canceled 2
Scheduled 3

Let us set the statuscode of a dynamic entity say "new_smartappointment" to done. CRM does not allow us to just set the status code to "Done". We also have to set the statecode to completed. To set these state code and status code we need to use SetStateDynamicEntityrequest class.

And here is how we do it:

SetStateDynamicEntityRequest req = new SetStateDynamicEntityRequest();
Moniker n = new Moniker { Id = id, Name = " new_smartappointment " }; // id here is a variable that stores the GUID of the record to be updated.
req.Entity = n;
req.State="Completed" //set the statecode
req.Status=2 // set the status code.
SetStateDynamicEntityResponse res = (SetStateDynamicEntityResponse)service.Execute(req);

Hope that helps some of you out there.

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

One comment on “How to programmatically set the status code field of a Dynamic entity”

PowerObjects Recommends