Update Business Process Flow stages using Power Automate
Recently, I have come across a requirement to update business process stage automatically on update of status field.
The status field is updated by external users via PowerApps Portal.
We can achieve this many ways . Writing custom code can be an option . But I thought of using Power Automate. ( Microsoft Flow is renamed to Power Automate ).
Quick note on Business Process Flow:
The method of retrieving and updating BPF fields within the record is deprecated. Read more on https://docs.microsoft.com/en-us/power-platform/important-changes-coming#legacy-process-related-attributes-in-entities-are-deprecated
The supported way is is to reference fields in the BPF entity that would have been created when your BPF was created.
Read more on https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/model-business-process-flows
Alright, lets understand the logic before configuring flow.
Here is my logic . Status value and their corresponding stage.
Trigger :
The trigger is when the status is updated.
Initialize variable to store Stage Ids and Status values:
Retrieve Business Process Flow instance record :
List Record action is used to retrieve BPF instance record associated with work order record.
Filter query is for the purpose of returning BPF instance record associated to work order.
Compose actions to retrieve BPF instance Id and Process Id:
Here are the expressions to retrieve BPF instance id and Process Id from the above List Record action.
BPF instance record id : first(body(‘Get_Work_Order_BPF_record’)?[‘value’]).businessprocessflowinstanceid
Process Id : first(body(‘Get_Work_Order_BPF_record’)?[‘value’])._processid_value
Get BPF Stages Ids dynamically :
We need to pass BPF instance record in the filter query.
Store BPF Stage Ids in Variables :
Apply for Each action is used to loop through the result got from above list record action and Switch Control is used to store stage ids in variables based on stage name.
Update BPF Stage based on Status value :
Here again, Switch Control is used to update stage according to status value.
And Update record action is used to update BPF instance record with stage id.
Traversed path :
The Traversed Path is a field as mentioned earlier that represents the life cycle of the business process flow as it contains the stage IDs the Business Process Flow as gone through. The Traversed Path field value needs to be updated to include the stage ID of the current active stage it will be moved to. This is the Review stage.To include the stage ID in the Traversed Path field the concat function is used in an expression.
For example, if BPF is moving from first stage to second stage , the expression should like below
concat(firststageid, ‘,’ ,secondstageid)
Conclusion :
If we follow the above steps , the total flow should like this.
Thank you for reading . Hope it helps.
Blog link : https://powerofpowerplatform.com/update-business-process-flow-stages-using-power-automate-microsoft-flow/
*This post is locked for comments