How to use a Workqueue in Power Automate
Tags: powerautomate, powerplatform, lowcode, rpa
Published: 2023-11-13 07:08:56

I've already spoke about how powerful a workqueue in Power Automate is [here](https://dev.to/wyattdave/power-automate-the-power-of-a-workqueue-4j1k), and this was before Microsoft released the functionality in the Power Platform. I was using custom tables/lists, but now Microsoft has prebuilt those tables for you, with some added sparkle.

But now its in general release I thought I would share how to use a workqueue in Power Automate, it is more aimed at Desktop flows (like other RPA tools, e.g Blue Prism, as you have limited resources that need to be managed), but that doesn't mean you can't or shouldn't use them in your cloud flows.

1. Setup
2. How to use
3. Trigger
4. Flow Action
5. Delete
6. Example

---

## 1. Setup
A couple of things to know, Workqueues require a premium license, and each queue needs to be setup.

The workqueue will be either under Monitor (old) or in the left menu. If it isn't there you can use this url:

`https://make.powerautomate.com/environments/{your environment ID}/monitor/work-queues`

![work queue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xts6adso3kx07qdz85gp.png)

We then create the workqueue (it can be used for one process or if you are brave multiple), additionally you can set an auto time out for items (that way the expire and wont be used any more, though I have never found a reason for this yet).

![create workqueue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10y3sywgd7h2i5obnt6j.png)

You now have your own workqueue, and best of all its own dashboard. This is one of the best benefits to Power Automate workqueues, from one screen you can see how your automation is performing. You can also share the workqueue so others can view the dashboard. 

![dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1un9j2yyw1adfgy3f7m.png)

The Advanced Details shows the guid (workqueue id) and key for the workqueue, these will be needed to process the workqueue.

![advanced details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sviv4tsc5t0e6ngd03as.png)

On top of viewing you can also edit the workqueue, so you can add items, delete them, and edit them. It can become a kind of control room for human in the loop actions if you need. e.g. items could be stacked up, when enough are ready a operator could log in, view all the ready items, categorise them and then release them to be processed by the next flow. This is one of the most powerful things the Power Automate Workqueue function adds, as you could replicate it all yourself with your own Dataverse table or SharePoint list, but you wont get the control room (without maybe a custom app).

## 2. How to use

The workqueue has a few predefined fields you can use:

![fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsdort7ako28os3ei5ms.png)

- Name -  I use as plane text key, it doesn't have to be unique but should help dashboard users track e.g email subject
- Priority - Low/Medium/Heigh, self explanatory but useful when you filter your queue
- Unique Id or reference - this does need to be unique and I use to link to other systems e.g. Email message id
- Expiration date - date & time when you want to auto stop processing the item
- Input - this is any data you may want to use throughout the process, I recommend creating a JSON that you then parse
- Processing notes - these are your tags, tags are used to identify where in the process the item is and helps trigger the next step

Example of input for email

```
{
  "from":{emailAddress},
  "attachment link":{sharepoint url},
  "body":{emailBody}
}
```

Example of Processing note tags for email

- Excel
- Word
- PDF
- RequestApproval


## 3. Trigger

To trigger our flows from the workqueue we are going to use the `When a row is added, modified or deleted` action.

![trigger action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d310mw9h506e4u9x8ydh.png)

Our first flow should be change type created, all future flows Modified. To ensure that our flows run at the right time we need to set trigger conditions. The conditions should in general include 3 conditions:

- Workqueue ID (so we only run on right queue as the tables are shared, this is from our Advanced Details)
- Status code (e.g so wont run if on Hold)
- Processing notes (uses the tag so runs right flow)

e.g.

```
@and(
	equals(triggerOutputs()?['body/processingresult'],'excel')
,
 	equals(triggerOutputs()?['body/statuscode'],1)
,
	equals(triggerOutputs()?['body/_workqueueid_value'],parameters('workqueueID (workqueue)'))
)
```

## 4. Flow Action
Once triggered we need to complete the action and update the item so that it can trigger the next flow/call Human in the Loop. Inline with trigger, we are using our standard Dataverse actions, this time `Update a row`.

![update row](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/88xsqbpth87e77y5waan.png)

We use `triggerOutputs()?['body/workqueueitemid']` as our Row ID, and the update our Processing Result with the next tag, and if needed the Status & Status Reason.


![status drop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1h0jzhle41agyv185it.png)

![status reason drop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awrxk2msqt7oy861va34.png)

To get our input data we use a simple `Parse JSON`

![parse json](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hich1clvmy84r8e7uvq.png)

You can update the data if need, just update the input field, though for best practice I try not too.

## 5. Delete

If we are processing a lot of items we can end up with a lot of data (and Dataverse is not cheap), so our workqueue should not be used as a data repository. If you need to record the information save it in a SharePoint list, SQL database, or another Dataverse table if you have lots of money 😎.

There are 2 ways to keep you queue tidy, delete each item when done, or clear the whole queue at the end of the process.

Deleting one item at a time we just use the standard Dataverse `Delete a row`action.

![delete item](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pffl78f931ep5gpuyn1x.png)

To do the whole queue could be more complicated, luckily Microsoft has your back with the Dataverse `Perform a bound action` action.

![cear work queue action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41qlmn690xbh4s56szbx.png)

Just select the 'Work Queues item' table, ClearWorkQueue action, and use the workqueue id from the advanced details.

## 6. Example
So when can/should we use a workqueue, I definitely recommend for large complex processes with lots of child flows. I also think anything with lots of Human in the Loop steps is a great use case. The other is related conditions.

A simple example would be:

We have a flow that can only run when 2 reports are received. They can come at anytime and in any order (so no cheating and running on the second report).

We have 2 flows, one that is triggered by emails. If the attachment is not valid it creates an item in the workqueue and sets Hold so a Human in the Loop can check. If they find it is the right report, with something like the wrong file name, they can update the item so that it continues in the process.

Next it checks to see if there are any queued items, if yes they update it, else it creates a new item.

The reports are added as tags, the second flow only runs when the Process Notes contains both of the reports.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p377hjzcok3kq6wjf0m8.png)

This is a very basic example, and there are other ways to do it, but having the functionality built in, and easy to scale (more reports, more steps) is really useful.

Overall workqueues may be best for Desktop flows (there because you have limited resources, you can use additional actions like 'get next item' and load balance those resources), but they are still very useful for cloud flows.

---

**Further Reading**
- [https://powerautomate.microsoft.com/en-ca/blog/microsoft-power-automate-work-queues-are-generally-available/](https://powerautomate.microsoft.com/en-ca/blog/microsoft-power-automate-work-queues-are-generally-available/)
- [https://learn.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/workqueues](https://learn.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/workqueues)