Change Business Process Flow Stage with Power Automate

How to automatically update the stage of a business process flow, efficiently, with only three steps in Power Automate. Trigger this flow however you want the only context you need is the ID of the if of the row whose business process flow you want to update.

Lets be clear, this is not new or novel breaking ground but each time I go to build this for a customer I find myself dredging through a lot of very dated/inefficient methods. The business process flow tables are a bit harder to interrogate for logical names than others (without going into XrmToolbox). Plus I know there is a better way, but I cannot remember which customer I built it for last and I don’t want to have to work it out all over again so here it is.

Get the business process flow row (businessprocessflowinstanceid)

One row can have many business process flows active at once, so there is no direct relationship between the row and the business process flow. However, only one instance of each business process flow can exist. Using a ‘List Rows’ action we can search for the correct row with a safe assumption that only one will ever exist. The name of the column which we use in the ‘filter rows’ query will vary a little depending' on the table the business process flow is based upon.

select _processid_value,businessprocessflowinstanceid

row count 1

filter rows for opportunity _opportunityid_value eq [OpportunityId]

filter rows for custom table _bpf_[CustomTableLogicalName]id_value eq [CustomTableId]

In the example above the custom table logical name is tcorp_procurement. The next two steps are the same regardless of the table the business process flow is based upon

Find the new stage row (processstageid)

Each stage in a business process flow is created as a row in the ‘Process Stages’ table, we need to find this. Using a ‘List Rows’ action we can search for the correct row (assuming you don’t have multiple stages in your business process flow with the same name, and if you do then you have bigger problem to deal with).

select processstageid

filter rows _processid_value eq @{first(outputs('GetBPF')?['body/value'])?['_processid_value']} and stagename eq 'Your Stage Name'

row count 1

Update the business process flow stage

So we now have two pieces of the puzzle we need to update the business process flow stage - the business process flow instance id and the stage id. Using the ‘Update a Row’ action - switch it!

Row ID: @{first(outputs('GetBPF')?['body/value'])?['businessprocessflowinstanceid']}

Active Stage (Process Stages): processstages(@{first(outputs('GetProcessStage')?['body/value'])?['processstageid']})

Previous
Previous

‘Distribution Lists’ in model-driven apps

Next
Next

Choices: Spreadsheet or CSV into Dynamics 365 JSON