How to avoid creation of duplicate Planner task with Power Automate
Posted On May 16, 2021
“I created a Power Automate flow to add a new task in MS Planner whenever an email is received, however, flow is creating duplicate tasks when a response/reply is received to the same email: I would like to avoid that.”
If you use flow to create tasks from incoming emails, you probably don’t want a new task for every email. The flow should create a task only from the original email, not from each reply to that email.
But how do you tell the flow to create just a single task, without duplicates? How does it recognize when it’s a new email and when it’s a reply?
Check if task already exists
The first thing to check is if the Planner task already exists. ‘List tasks’ to get all existing tasks, and then ‘Filter array’ to filter tasks by their title. Power Automate doesn’t offer any direct tasks filter, that’s why you need two actions (unlike e.g. with SharePoint items).
Let us assume that the tasks use the email subject as their title, therefore, Title is equal to Subject.
Once you filter the tasks, you should add a ‘Condition’ to check if the filtered array is empty. Empty output from ‘Filter array’ means there isn’t any task with the title and you should add it. If it’s not empty, the task already exists and you don’t have to do anything.
You can use the length(…) expression to check if the output length (number of tasks) is greater than 0.
Don’t create a task for reply email
It gets a bit complicated with reply emails. The process above will find only exact match between the task title and the email subject. But reply emails don’t have the same subject, they’ve got ‘RE:’ or ‘Re:’ as the subject prefix. And since you don’t want ‘Task’ and ‘Re: Task’ in your tasks list, you must handle also the replies.
Add another ‘Condition’ into the ‘is empty’ branch to check if the subject starts with RE: or Re:. If it does, don’t create a new task, it’s a reply to another email. If it doesn’t, create the task.
Note: the reply prefix depends on your regional / language settings, adjust it accordingly.
Following the approach above you can avoid creation of duplicate Planner task in any Power Automate flow. In this post it was using incoming emails for the tasks, but it’ll work with any source or a template.
It’ll be actually easier with other sources. Without the replies you can rely on the unique task title and stop with the first ‘Condition’.