Dataverse Desktop Flow Power Automate Power Automate Desktop
Manish Solanki  

How to retry work queue item in power automate desktop flow?

Use Case

The “Requeue item with delay” pattern delays the execution of work queue item but does not define the max attempts for its processing. In the below example, I have demonstrated the technique to stop reprocess work items after certain attempts. To achieve that, we can use ‘requeuecount‘ property as max retry count and notify business after crossing max retries attempts.

Prerequisites

A work queue with a work queue item to store the ID of ‘Employee’ database table. The value of the work queue item holds the employee Id which is being used in the SQL query to fetch the record:

Solution

1. Create a new Power automate desktop flow and add “Set variable” action to define the max retries count for work queue items. Enter variable name as ‘MaxRetryCount’ and set its value as 3:

2. Next, add “Process work queue items” action and select work queue from the drop down:

3. Post that add “Get a row by ID from selected environment” action to retrieve work queue item row from Dataverse. Select environment & choose table name ‘Work Queue Items’ from drop down. Pass the value of work queue item id dynamically as shown below:

%WorkQueueItem.Id%

4. Following that add “If” action to compare the requeue count with max retry count variable:

Enter the below code in ‘First operand’ and ‘Second operand’:

First operand:
%GetItemWithOrganizationResponse.requeuecount%

Second operand:
%MaxRetryCount%

Inside “If” block, add cloud connector “Send an email” to notify business users when max retries has reached. Set the appropriate value in ‘To’ & ‘Subject’ input parameters:

Enter below code in the ‘Body’ paramater:

The record '%WorkQueueItem.Value%' does not exists in the database.

The last action in the ‘If’ block is to update the status & processing notes of the work queue item. Select work queue item from the drop down. Choose the status as ‘Business Exception’:

Enter the below code in the ‘Processing notes’ parameter:

Failed to find record after %MaxRetryCount% retries.

5. Add “Else” action in between “If” and “End” block to fetch the record from the SQL database. Inside else block, add “Open SQL connection” action to connect to sql server. Enter connection string in the input parameter:

Now, add “Execute SQL Statement” action to execute the SQL query. Set SQL connection variable in the ‘SQL connection’ input parameter. Dynamically, pass the value of work queue item in the where clause as shown below:

Add another “If” action to check the record return from the output of previous action. Dynamically, pass the row count property and compare it with 0:

Inside “If” block, add “Get current date and time” action to get the current date & time stamp:

Add 5 minutes to current date time variable using “Add to datetime” action. Pass the value of current date time value in the input parameter. This variable holds the delay time stamp for processing work queue item. Please add the delay time as per your requirement:

Add “Requeue item with delay” action to requeue work item in the queue for processing. It will delay the execution of the work item based on the time stamp set in ‘Delay until’ parameter. Set all input parameters as shown below:

The overall structure of the desktop flow will look like:

Output

The status & details of work queue item is shown below after 3 unsuccessful retries:

Details of processing notes:

Email notification sent to users on business exception:

Conclusion

We can use “requeuecount” property for setting up retry mechanism for work queue items in desktop flow. This will prevent indefinite retries using “Requeue item with delay” technique. By setting retry mechanism, we can notify users about the failure transaction so that they can take the corrective action on time.

Leave A Comment