Dynamics CRM 2016 – Using SetProcessRequest message to update your Business Process programmatically

Exploring new stuffs in Dynamics CRM 2016 is great and if it is something technical and gives me an opportunity to write some code, it’s like icing on the cake for me.

CRM 2016 has introduced the new SetProcessRequest message which enables you to set the business process of a target entity. So let’s get into some action here.

I will demo this with the opportunity entity. The opportunity entity has a default process of “Opportunity Sales Process”. Below is the opportunity record loaded with the same business process.

image

 

So I created another business process flow for the opportunity entity called “Opportunity Business Process Flow” I will switch the business process of the record for the above record to this new process.

var service = GetService();

            SetProcessRequest req = new SetProcessRequest();
            req.Target = new EntityReference("opportunity",Guid.Parse("7059510E-59A3-E511-80E4-3863BB35AD90"));
            req.NewProcess = new EntityReference("process", Guid.Parse("AEC906DF-5C10-490D-8D0E-E5620FAAE614"));

            var resp = service.Execute(req);

 

So once we open the record again, the new process is loaded.

image

 

So what about the workflows or plugins registered on change of processid of your application? SetProcessRequest will fire the update message and any workflows registered on change of processid would trigger.

Happy exploring CRM 2016.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s