How to automatically retrigger the failed unattended desktop flow?
Use Case:
A need for an automate solution to retrigger unattended desktop flow from cloud to reduce the efforts & execution time of operational or support team.
Scenario:
In current scenario, there are many unattended Power Automate desktop flows running in the production environment. Those unattended desktop flows are being triggered from scheduled cloud flows.
For auditing purpose, we will maintain the SharePoint list to store the details. Title column will store the name of the schedule cloud flow that will be resubmitted
Solution:
We will create an automated cloud flow that triggers on the failure of desktop flow. The flow will resubmit the failed cloud instance containing the action to run desktop flow.
Flow creation steps:
1. Create ‘Automate cloud flow’ and set the trigger as ‘When a row is added, modified or deleted’. We need to set change type parameter as ‘Modified’ to restrict trigger this flow when status is modified as failed. The table ‘Flow Session‘ stores the details of desktop flows so select it in ‘Table Name’ parameter. To reduce the flow trigger, set the ‘Filter rows’ parameter. The code 8 represents the failed status code:
For details on status code, refer the link: flowsession table/entity reference (Microsoft Dataverse) – Power Apps | Microsoft Learn
2. Next, add “List rows” action to get the name of the parent cloud flow from ‘Process‘ table. Search for cloud flow name by applying filter query on resourceid column. From the trigger, we get ‘context’ object that holds various information like machine name, mode, parent cloud flow workflow id & run id, mode etc. This step is just to get the name of the cloud flow so that we can store it in the audit list:
Just copy & paste the filter query in the textbox:
resourceid eq '@{json(triggerOutputs()?['body/context'])?['parentWorkflowId']}'
3. After that, add “Apply to each” action to iterate the array return by “List rows” action and pass the value object from the output of previous action:
Add “Resubmit flow” action to resubmit the cloud flow. We will use expression to store the value in ‘Environment’ parameter:
Below expression needs to be added in the expression box as highlighted in the above screenshot:
workflow()?['tags']?['environmentName']
Similarly, set expression for other parameters in “Resubmit flow” action.
Flow:
json(triggerOutputs()?['body/context'])?['parentWorkflowId']
Run ID:
json(triggerOutputs()?['body/context'])?['parentWorkflowRunId']
Finally, create an item in SharePoint list for audit purpose. Dynamically pass the process name from the output of list rows action:
Enter below expression for setting the ‘Environment Id’ column:
workflow()?['tags']?['environmentName']
Output:
The automated resubmit cloud flow will resubmit the cloud flow and store its entry in audit SharePoint list:
Conclusion:
Using Dataverse premium & admin connector, we can build a framework for resubmitting the failed unattended desktop flows. This will help in reducing the effort & execution time for support activities.
This is just the basic solution, but we can enhance it by incorporating:
- Limit on number of retries to avoid infinite resubmit trigger
- Incorporate master list to enable resubmit framework for only critical flows
- Restrict resubmit based on the error codes return by the failed desktop flow