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.
- Value 1
- Value 2
- Value 3
There are three BPF’s for Account. So basically the logic goes like this.
- If account is created with Value 1, then BPF 1 should be applied
- If account is created with Value 2, then BPF 2 should be applied
- If account is created with Value 3, then BPF 3 should be applied.
- 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:
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)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.
Very Informative. Thanks Debajit.
Thanks for this blog….Can u please provide the code implemented for this requirement ? It would be helpful .
Hi Kiti,
Thanks for reading my blog. Please follow this one – https://debajmecrm.com/2020/06/24/skip-setting-a-business-process-flow-during-record-create-in-dynamics-365-cds-this-simple-trick-may-help-you/.
Here I have shown how to skip. However instead of Guid.Empty u just need to set the appropriate Guid for the process.
Cheers
Debajit