When using Power Automate to create flows, you may have noticed a frustrating occurrence where multiple emails are sent during the flow’s execution. This issue arises specifically when your flow sends an email for each item retrieved through the SharePoint Get item action. For instance, if your flow includes a loop that runs five times, retrieving five list items, and then utilizes the Outlook action “Send an email” within the Apply to each loop, a total of 25 emails will be sent.
When a flow is run, it will send an email for each item returned by the SharePoint Get item action in your flow.
When a flow is run, it will send an email for each item returned by the SharePoint Get item action in your flow.
This is a good thing! You can use this to your advantage. You can create complex workflows that are triggered by emails and then perform manual tasks like creating reports or sending out emails based on certain conditions (e.g., if there were no errors when you ran the workflow).
When you create a flow that uses the SharePoint request or trigger, each list item returned will give a matching output.
The SharePoint request or trigger is a flow action that utilizes the SharePoint API to fetch an item from a list. When you integrate this action into your flow, each retrieved list item will produce a corresponding output.
Here’s a breakdown of how it works:
When you employ a flow action that generates multiple results, PowerApps creates multiple duplicates of your data and sends them in separate emails. For example, if you configure an email action to send an email for each new person added to your contacts list, whenever someone adds themselves to the list, an email will be sent to them (the first time). Furthermore, if they add themselves again, which can happen multiple times throughout their daily activities, another email will be sent accordingly.
This situation can create a problem when there is a loop within your flow. For instance, if you have a flow containing an Apply to each loop that executes five times with five list items, and within this loop, you utilize the Outlook action “Send an email,” it will result in the sending of 25 emails (5 items * 5 iterations of Apply to each).
This can cause an issue if you have a loop in your flow. For example, if you have a flow with an Apply to each that runs five times with five list items, and then uses the Outlook action “Send an email” inside the Apply to each, this will send 25 emails (5 items * 5 iterations of Apply to each).
In this situation, Power Automate will send multiple emails because it doesn’t know which iteration of the Apply-to-each is actually sending the email.
To overcome this issue, you can implement a workaround by incorporating a Compose action before the Outlook action. This will ensure that despite having multiple items from the SharePoint request or trigger, only one item is returned. As illustrated below:
To resolve this problem, you can use a workaround by including a Compose action before the Outlook action. By doing so, the Compose action ensures that only one item is returned, regardless of the multiple items obtained from the SharePoint request or trigger. To implement this solution, simply add a Compose action with the value: items(‘Apply_to_each’)?[‘Id’].
Subsequently, this single item will be utilized by all subsequent actions and can be sent as an attachment, guaranteeing the sending of only one email.
Final Words
By implementing this solution, you can effectively avoid the issue of sending multiple emails while using Power Automate. If you have any questions or need further assistance, feel free to reach out to our Support team at support@powerautomate.com.
Leave a Reply