Introduction
In this article, we will go through a quite simple use case on how to set up a variable value without using conditional checks. Please note that this might not be suitable for all the scenarios but could be helpful in specific scenarios where the flow nesting limitation has reached its maximum level, which is eight, or in any other conditions where the conditional check can be avoided.
Method 1. With condition action
Let us go through the following steps to depict the normal scenario.
Step 1. Log in to the Power Automate maker portal https://make.powerautomate.com
Step 2. Click on ‘Instant cloud flow’ --> ‘Manually trigger a flow’.
Step 3. Initialize the variable called ‘strApprovalStatus’ and leave the value blank.
Step 4. Add action ‘Start and wait for approval’.
Step 5. Select the first condition, which is everyone must approve.
Step 6. Assign the approval to yourself or any other service account to which you have access. The condition here is to check if the outcome is approved, then usually we use conditional checks to set the variable values. Later, these variables can be used to set values in Dataverse tables, or SharePoint lists, or anywhere else where the PowerAutomate has a connector.
Step 7. Add the conditional check to set the final approval status. Select the ‘Outcome’ from Dynamic content and check for ‘Outcome’, which contains ‘Reject.’ Here, I am using a variable called “strApprovalStatus”. Use action ‘Set variable’ and in the right branch set the value to ‘Approve’ and in the left branch set the value to ‘Reject’.
Step 8. Below is the overall configuration of the flow.
Testing
Step 1. When approved, the output run for the flow is below.
Method 2. Using Dynamic Expression
The advantage of this method is that we can skip conditions and therefore, avoid one nesting level of Power Automate. The nesting level occurs when any of the following actions are used.
- Apply to each
- Condition
- Do Until
- Scope
- Switch
Step 1. Edit the flow design from the previous Method 1 and remove the ‘Condition’ action.
Step 2. Add Set variable action. Edit the action and rename it to ‘Set variable-strApprovalStatus' in the expression, and enter the following expression.
if(contains(outputs('Start_and_wait_for_an_approval')? ['body/outcome'], 'Reject'),' Rejected', 'Approved').
It says if the outcome contains ‘Reject’ set the status to ‘Rejected’ or else set it to ‘Approved’.
Step 3. Log the variable status to check.
Step 4. The overall design looks like the one below.
Testing
Step 1. When approved, the variable strApprovalStatus should be set to ‘Approved’.
Step 2. When rejected, the variable strApprovalStatus should be set to ‘Rejected’.
Conclusion
Thus, in this article, we have seen how to avoid conditional action in Power Automate to set the variable value based on the approval outcome. This can be extended to more advanced scenarios. Please feel free to comment on any issues or for any ideas that you may have.
References