Duplicate Detection in Logic App Trigger
Overview
In certain scenarios, a Logic App may process the same item multiple times due to various reasons. Common examples include:
- SharePoint Polling: The trigger might fire twice because of subsequent edits.
(Reference: Microsoft SharePoint Connector for Power Automate | Microsoft Learn) - Dataverse Webhook: This can occur when a field is updated by plugins.
Solution Approach
To address this issue, I implemented a solution using the Logic Apps REST API:
Workflow Runs - List - REST API (Azure Logic Apps) | Microsoft Learn
The idea is simple:
Each time the Logic App is triggered, it searches all available runs within a specified time window for the same clientTrackingId.
Implementation Details
Step 1: Extract clientTrackingId
For the SharePoint trigger example, I used the file name as the clientTrackingId with the following expression:
@string(trigger()['outputs']['body']['value'][0]['{FilenameWithExtension}'])
Step 2: Pass Payload to Duplicate Detector Flow
The payload includes:
- clientTrackingId (chosen identifier)
- Resource URI for the SharePoint flow
- Time window to check against
Duplicate Detector Flow Logic
The flow retrieves the run history and checks if the number of runs is greater than 1. If so, the same file was processed before:
the http response will have the below status
if(greater(length(body('HTTP-Get_History')['value']), 1), '400', '200')
Important Notes
- The Duplicate Detector Flow must have Logic Apps Standard Reader (Preview) permission for the resource group.
- The solution is built on Logic App Standard, but it can be adapted for Logic App Consumption or Power Automate.
GitHub Link
logicappfiles/Logic Apps Duplicate Detector at main · mbarqawi/logicappfiles