Power Automate: Cloud Flows | Terminate Unnecessary Runs


The ask, address a Power Automate cloud flow that needlessly continues to run even when there’s no data to process. This particular flow is an Automated cloud flow, and it runs daily, emailing a dynamic list of people a digest report of SharePoint Online list items created the day prior.

The flow is triggered, then a Get Items action returns an array of recently created items. Afterwards, the flow returns an array of email recipients and formats the digest email before sending a personalized email to each person. Relatively straight-forward automation, but if no newly created items are returned, does the flow care to query the digest recipients or format their emails? It doesn’t.

Figure 1 - Power Automate cloud with Scope controls and a Get items action.
Figure 1Power Automate cloud with Scope controls and a Get items action.

So, how can the maker stop their flow if no recently created items are returned? Well, they could use the Terminate action, which offers several “Status” options, visible in the flow’s run history, indicating whether the flow was successful or not:

Figure 2 - Power Automate cloud flow Terminate action.
Figure 2Power Automate cloud flow Terminate action.

Now, if the Get items action throws an error, which would be a problem, then a Terminate action could be added with a status of “Failed”, terminating the flow because no items were returned:

Figure 3 - Power Automate cloud flow with Scope controls, Get items action and a Terminate action.
Figure 3Power Automate cloud flow with Scope controls, Get items action and a Terminate action.

Otherwise, the Get items action is successful. However, again, what if there are no recently created items returned? Well, to check, use the length() function and count the number of returned array items:

Figure 4 - Power Automate cloud flow Condition block with length() function for Get items array.
Figure 4Power Automate cloud flow Condition block with length() function for Get items array.

If the returned array is empty, length of zero, then the flow doesn’t need to proceed. Though, because there were no errors, the maker shouldn’t Terminate the flow with a status of “Failed.” Rather, they should specify “Cancelled”:

Figure 5 - Power Automate cloud flow Condition block comparing length() of Get items array to 0.
Figure 5Power Automate cloud flow Condition block comparing length() of Get items array to 0.
Figure 6 - Power Automate cloud flow with Scope control, Condition block, and Terminate action.
Figure 6Power Automate cloud flow with Scope control, Condition block, and Terminate action.

Conclusion:
Even for cloud flows that aren’t expected to fail, it is good practice to terminate them if there are no necessary actions left to perform. This helps save Azure resources as every action requires an API call and helps the flow generally be more efficient.

“The way to right wrongs is to turn the light of truth upon them.”

Ida B. Wells

#BlackLivesMatter

Leave a comment