State Machine workflow implementation in MS-flows

Loading

Requirement : when the User need an Approval email for ‘multiple approvers’ and ‘multiple approvers’ wants to send back to the previous approvers. The options available are like Approve, Reject, Send back to Approver, So when the one or the other approver select the send back to ‘previous approver’, the flow have to retrigger and get back to the previous approver and then the scenario of the flow start and continue in the sequence of the created conditions.

state Machine > where it is a requirement depends on the condition and retriggering the workflow many number of times, I will create for three level approvals in the workflow L1, L2 & L3.

I have created a SharePoint list with required basic columns along with the column with choice field where I require to use as a condition in the PowerAutomate by default the choice would be Pending with 1st Approver

In my list, the column which used as a condition is ApprovalStatus and the choice fields are

  • Pending with 1st Approver
  • Pending with 2nd Approver
  • Pending with 3rd Approver
  • Completed
  • Reject

Now creating the MS-Workflow using the above list from SP

* Note: do not build the conditions in nested format

create a new Automated workflow -> action to be used- when an item is created or modified

“The above action works as a retriggering the workflow based upon the given condition – created or modified”, so when an item is edited in the SharePoint list the flow would check and retriggers it.

Insert a condition and take the ‘ApprovalStatusvalue’ is eq to Pending with 1st approver, as the column consists of the choice, so the output will be as the selected values.

Condition1:
ApprovalStatusvalue- is equal to - Pending with 1st Approver

> Now take the start and wait for an approval action in the ‘Yes’ statement branch for the approval process (I have filled with the required fields inside the action)

>Next fetch the ‘outcome’ response of the L1 approval response into the condition as outcome is eq to Approve

>I will next take the action ‘update item’ in the ‘Yes’ statement branch

>As the default responses were Approve and Reject , the ‘update item’ has to update the properties when the response is approved by the L1 Approver

>I have updated the required fields in the action and the important is here, update the ApprovalStatusValue as Pending with 2 nd Approver from Pending with 1st Approver, So this will update the column ApprovalStatus in SP list.

> Till the update item the 1st condition completed

>Next I will use another condition below the 1st condition and named as condition 2 and the condition would be ‘Approvalstatusvalue’ is eq to “Pending with 2nd Approver” as below

Condition2:
ApprovalStatusvalue- is equal to - Pending with 2nd Approver

>the above condition will check the value and pass to the ‘yes’ or ‘no’ statement field.

>Next Insert the action ‘start and wait for an approval for L2’ in the ‘Yes’ statement , I will use the custom response for this approval, as I need the response button of my own choice in the approval email.

>I created the custom response as required below

  • Accept
  • Reject
  • Send to 1st approver

Next action ‘switch’ has taken to check the responses and pass the condition to the next level

In the above ‘switch’ action, the cases used for the required action values

In Switch action used ‘outcome’ from the L2 to match the values from the responses and pass for the next level

I have added the action ‘update item’ in each case to update the value of ApprovalStatus column in SP as per required outcome selected in the Approval email from the three options

Accept, Reject & Send to 1st Approver

>while click on Send to 1st Approver button from the response in Approval email, the ApprovalStatusValue gets updated with -‘pending with 1st Approver’ in SP list and the flow would retrigger.

Update item -Send back to 1st approver has added in case action

> while click on Reject button from the response in Approval email, the ApprovalStatusValue gets updated with -‘Reject’ in SP list and the flow would stop.

Update item – 1st approver Reject has added in case2 action

>while click on Approve button from the response in Approval email, the ApprovalStatusValue gets updated with -‘pending with 3rd Approver’ in SP list as the second Approver has approved next it would go to level 3 approver

Update item 6 has added in default case action, because default action used apart from the two action cases (we can add up the cases depend on our requirement and the responses)

Here comes the 3rd Condition for level 3 approver

>Next I will use another condition below the 2nd condition and named as condition 3 and the condition would be ‘Approvalstatusvalue’ is eq to “Pending with 3rd Approver” as below

Condition3:
ApprovalStatusvalue- is equal to - Pending with 3rd Approver

I created the custom response as required below (four required responses)

  • Approve
  • Reject
  • Send to 1st approver
  • Send to 2nd approver

Next action ‘switch’ has taken to check the responses of L3 approver values

In the above ‘switch’ action the cases used for the required action values

In Switch action used ‘outcome’ from the L3 to check the values from the responses

I have added the action ‘update item’ in each case to update the value of ApprovalStatus column in SP as per required outcome selected in the Approval email from the three options

Accept, Reject, Send to 1st Approver & Send to 2nd Approver

>while click on Send to 1st Approver button from the response in Approval email, the ApprovalStatusValue gets updated with -‘pending with 1st Approver’ in SP list and the flow would retrigger.

Update item -Sent to 1st approver has added in case action

>while click on Send to 2nd Approver button from the response in Approval email, the ApprovalStatusValue gets updated with -‘pending with 2nd Approver’ in SP list and the flow would retrigger.

Update item -Sent to 2nd approver has added in case2 action

> while click on Reject button from the response in Approval email, the ApprovalStatusValue gets updated with -‘Reject’ in SP list and the flow would stop.

Update item – 3rd approver Reject has added in case3 action

>while click on Approve button from the response in Approval email, the ApprovalStatusValue gets updated with -‘Completed’ in SP list as the third Approver has approved and the flow succeeds

Update item 9 has added in default case action, because default action used apart from the three action cases (we can add up the cases depend on our requirement and the responses)

Final outputs will be when the ‘multiple users’ select on ‘send back to 1st approver’ by the 2nd Approver or send back to 1st approver’ by the 3rd Approver or send back to 2nd approver’ by the 3rd Approver .

The values gets updated according to the selection of the approver into the Sharepoint list through the ‘start and wait for an approval’ email (Custom responses).Thus when the Sharepoint list (ApprovalStatus-column) gets updated the flow would retrigger and continue on till the process completed.

Leave a Reply

Your email address will not be published. Required fields are marked *