Friday, February 7, 2020

Set the BPF and Stage through Power Automate for Dynamics 365 CRM

The MS documentation clearly specifies, that the setting BPF/stage is not supported.
This method uses the deprecated Process Id field of an entity for which the BPF is to be set(Only way).
Hence, with future releases the functionality might not work.

Let's consider a Custom entity- Application as the target to set the BPF for.
AS we created a workflow of category BPF (Let's assume we create one with Name "Application Flow")for an entity, System automatically creates an entity to store the BPF information.
For each of the Application record, one record(instance) of the activated BPF will be created and associated automatically.
The  last BPF instance created with Status "Active" is what shows up on the Form, also filtered additionally by the Security Role.
The stages of all the BPF in the System are referenced using Process Stage entity.

The BPF instance has a lookup to :
-The main entity
-Stage entity
-Process (The GUID of the Workflow)
which helps have the references.

To set the BPF  stage for an entity, we need to :
-Retrieve the existing Flow instances associated with the record and delete them,
-Retrieve the stage Id - passing the name of the stage.
-Create a new instance of the BPF , setting the main entity lookup field, Name, Stage Id, Status -Active,Workflow Id and then associate this new instance with the main entity additionally - by setting the Process lookup Field.
Please see the steps oulined below.