{Know How} Apply Business process flow on create of a record or skip setting of default Process flow based on custom business logic in Dynamics 365 using ProcessId field of record

Business Process flows are used everywhere and as a Power platform consultant you might be working with them almost everyday.

However sometimes the intricacies of the most mundane stuffs seems to baffle us. And one of them is was this requirement that I recently had. And trust me I found many was not aware of the solution.

So the customer here wanted to apply Business process flow to a record based on some business logic. Let’s understand the full requirement first before I go ahead with the solution.

So the customer have field on Account entity. Let’s say field name is “BPF Indicator”. It’s an option set field. And let’s assume there are three values for this field.

  1. Value 1
  2. Value 2
  3. Value 3

There are three BPF’s for Account. So basically the logic goes like this.

  1. If account is created with Value 1, then BPF 1 should be applied
  2. If account is created with Value 2, then BPF 2 should be applied
  3. If account is created with Value 3, then BPF 3 should be applied.
  4. If no value is selected, setting BPF for the record should be skipped.

The accounts could be created through integration, data import and also admin can set it up from UI.

Of the three Business Process Flows enabled for account entity, BPF1 was the highest in order. So it is kind of default Process flow for account.

What we did initially was to use the SetProcessRequest in our plugin to set the appropriate BPF. But what is the problem with that? The main issue with that is the process instance for the default Business process flow which in this case is BPF 1 was also getting created.

Say an account named “Account 1” is created with “BPF Indicator” = Value 2. We were using SetProcessRequest method to set BPF 2 for account record. But when we checked Advanced find, we found that two process instance records for Account 1 got created. One for BPF 1 which is the default one and the other for BPF 2.

So how do we remove the default process for being applied at all. A lot of searching but trust me it’s again docs which came to my rescue. Link below:

https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/model-business-process-flows#apply-business-process-flow-while-creating-an-entity-record

So the gist is to make use of the ProcessId field of the record. Surprisingly while the field is deprecated, it is still the deciding factor while setting the BPF for a record. All I did was to create a plugin on pre-operation stage of account create and set the appropriate value of processid.

So if I need to set the BPF as BPF 2, all I need to do is set the process id field to the value of process guid for BPF 2. If you don’t want to apply BPF for a record, you would need to just set is as Guid.Empty.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

One thought on “{Know How} Apply Business process flow on create of a record or skip setting of default Process flow based on custom business logic in Dynamics 365 using ProcessId field of record”

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