How to prevent duplicate items in a Blue Prism queue
Before you add new items from some source data to a queue it may be important to first check whether any of the items you want to add are already on the queue.
An item is considered a duplicate if the Item Key is the same.
Remember when you set up the queue in the System Manager you provide a field from the data (Key Name) that becomes the Item Key.
In the example to follow we want to add the rows in a collection called “CSV Values” to the queue without adding any duplicates.
You first check whether the new item is already on the queue using the Is Item on Queue action. This action is found in the Work Queues business object.
The compulsory inputs to this action are:
The rest of the inputs control which type of items you want to include in the search. The default for each of these is True.
The output of this action is a flag indicating whether it found a duplicate or not. You can also store the Item IDs of all the duplicates. It depends on how you want to handle duplicates as to whether you need to store these IDs. If you just want to avoid adding any duplicates, then you just need a Data Item for the Result output.
This action needs to be placed inside a Loop since it can only check one key value at a time. Set the Loop Start to work through the collection containing the rows you want to add to the queue (in this example it would be CSV Values).
After the action you will need a Decision stage which uses the output of the action.
The rest of the steps in the Loop depends on what you want to do if there is already an item on the queue. One option is to simply not add the duplicate item. However, if the one already on the queue was processed a while ago and it may be appropriate to add this new one. In this article I will only cover adding the non-duplicates.
It might seem like all you have to do is link the no path from the decision to an Add Data to Queue action. The problem is that this action adds the whole collection to the queue and not just the row the loop is busy with.
To get round this you need to have a separate collection (e.g. Item for Queue as per picture below) to temporarily store the data from the current row of the loop. Set up fields in that collection to match the fields of the source data. You do not need to add an initial value.
You first need to add a new blank row to this collection.
Use the action Add Row found in the Collections object.
Then using a Multi Calc stage you can transfer the data in the current row of the loop (i.e. CSV Values) to this Item for Queue collection.
You will then use an Add to Queue action. Note that the data added is the Item to Queue collection which is being used to store the current row of the loop.
You can get more information about the other inputs from the article “Using a queue in a Blue Prism process”.
Finally, you must remove the row from the Item for Queue collection. This is to ensure that you only ever have the current row of the loop stored in this collection.
By the end of this loop you should only have added data that does not already exist on the queue.