Add and Retrieve Work Queue Items
Desktop Flow Power Automate Power Automate Desktop
Manish Solanki  

How to add multiple work queue items & filter work queue items based on query?

Use Case

In Power Automate Desktop version ‘2.49.176’, two new actions for work queue have been introduced:

  • Add multiple work queue items
  • Get work queue items by filter

In this article, I will demonstrate how we can use those actions to add work queue items directly in Power Automate Desktop without using loops and improve efficiency in automation. We can also fetch the items from work queue without using cloud connector in PAD.

Scenario

A work queue “Work Queue 1” is already set up in power platform ‘Test’ environment:

Work Queue in Power Automate Environment

Solution

Let’s explore both actions in details.

1. Add multiple work queue items

The action “Add multiple work queue items” can be used for adding items in work queue by avoiding loops. This action allows users to add work queue items directly from the data table.

Following is the schema or structure of data table it accepts:

Column NameDescriptionRequired?Allowed Values
NameThe name of the work queue item.NoAny string
InputInput details or data for a work queue item.YesAny string
Expires in
Specifies the expire date time of an item.NoDate and time value
Processing notes
Processing notes related to the item.NoAny alphanumeric string
Priority
The priority level of the item.YesNumeric value:
100 (High)
200 (Normal)
300 (Low)
Unique reference
A unique identifier or reference value for an item.NoAny unique alphanumeric string or reference
Status
Status of an item on adding it.YesNumeric value:
0 (Queued)
1 (On Hold).
Delay until
Specifies date and time until the work queue items should be ignored for processing.NoDate and time value
Data table schema of work queue item

The mandatory columns are: Input, Priority & Status. The action “Add multiple work queue items” fails if values are not provided for those columns.

You can just copy and paste the below code in PAD to create a data table action:

Variables.CreateNewDatatable InputTable: { ^['Name', 'Input', 'Expires in', 'Processing notes', 'Priority', 'Unique reference', 'Status', 'Delay until'], [$'''''', $'''''', $'''''', $'''''', $'''''', $'''''', $'''''', $''''''] } DataTable=> WorkQueueItemDataTable

After creating the data table, add some rows with sample data as shown below:

Sample work queue items

Or you can copy & paste the below code to directly create a data table with sample data:

Variables.CreateNewDatatable InputTable: { ^['Name', 'Input', 'Expires in', 'Processing notes', 'Priority', 'Unique reference', 'Status', 'Delay until'], [1, $'''Item 1''', $'''''', $'''''', 300, $'''''', 0, $''''''], [2, $'''Item 2''', $'''10/20/2024 2:30:00 PM''', $'''''', 300, $'''''', 0, $''''''], [3, $'''Item 3''', $'''''', $'''''', 300, $'''''', 1, $''''''], [4, $'''Item 4''', $'''''', $'''''', 300, $'''''', 1, $''''''], [5, $'''Item 5''', $'''''', $'''''', 300, $'''''', 0, $''''''] } DataTable=> WorkQueueItemDataTable

Now, add “Add multiple work queue items” action & choose the work queue from the drop-down list in first parameter. Pass the data table variable in second parameter as shown below:

Input variable of Add multiple work queue items action

Expand ‘Variable produced’ to see output variable generated by this action. Toggle on switch for all output variables:

Output variables of Add multiple work queue items action

Save & run the flow to test the result.

Output:

All 5 sample work queue items were saved successfully:

Work Queue Output

The action ‘Add multiple work queue items’ produced 3 output variables.

1. The output for variable ‘FailedWorkQueueItems’ was empty list as all items were successfully saved in work queue:

2. The output of ‘HasFailedItems’ was false as no item was failed during flow execution:

3. As all 5 sample work queue items were saved successfully so output variable ‘SuccessfulWorkQueueItems’ returns the list of objects for all those items:

let’s explore how “Get work queue items by filter” action works to retrieve items from work queue.

2. Get work queue items by filter

This action allows users to retrieve work queue items based on the filter query. The filter query will be in the form of FetchXML filter expression.

Add “Get work queue items by filter” action and select work queue name from the drop-down list. In the second input parameter, add a fetchXML expression to get the items whose status is set as ‘On hold’:

<attribute name="statecode" />
<attribute name="uniqueidbyqueue" />
<attribute name="createdon" />
<attribute name="completedon" />
<attribute name="workqueueitemid" />
<attribute name="executioncontext" />
<attribute name="name" />
<attribute name="expirydate" />
<attribute name="processingresult" />
<attribute name="priority" />
<attribute name="statuscode" />
<attribute name="modifiedon" />
<attribute name="processingstarttime" />
<attribute name="retrycount" />
<attribute name="requeuecount" />
<attribute name="input" />
<attribute name="delayuntil" />
<filter >
    <condition attribute="statecode" operator="eq" value="3" />
</filter>

Here, statecode is the logical name of ‘Status’ column and value 3 represents ‘On hold’ value of status column.

You can set the number of items to be retrieved from this action by expanding ‘Advanced’ option. The default value of this parameter is 5000.

Save & run the flow to test the output.

Output:

This action returns a list of 2 items having ‘On hold’ as the status:

Click ‘More’ link button for the first element and verify its status:

Conclusion

Using “Add multiple work queue items“, we can add items in work queue in batches directly in desktop flow without using loops. This action will save the time in adding multiple items in work queue and there by improve the efficiency of the process.

Using “Get work queue items by filter” action, we can filter the work queue items by applying fetchXML expression. This action allows uses to retrieve one or multiple items from work queue directly and avoid using cloud connector in desktop flow

Leave A Comment