cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
somedudeWA
Frequent Visitor

Unwanted 'Apply to Each'

Hi

 

I am trying to create a simple power automate flow that sends a customised email to a when a specific field is update in a SharePoint list. I keep getting unwanted ‘Apply to Each’ loops when I go to send the email. (I am basically trying to create a simple help desk/ticketing system, but the examples in the forums/youtube don’t quite meet my requirements.)

 

My SharePoint list automatically captures an incoming email (a general support request) and breaks the information into applicable columns (email from, email subject, email body etc). A team manager then adds some task instructions via another column and identifies an officer to carry out the task (person or group column).

 

I have a yes/no column that is set up as the condition to ‘trigger’ the sending of the task or email, but once I try to configure the email under the ‘yes’ condition and add the field that has the ‘task assigned to’ username email variable power automate adds the ‘apply to each’ loop which causes multiple emails to be sent, which is undesirable.

 

Is there a straight forward way to switch off the automatic Apply to Each or some other way to avoid it? Or do I need to do an array and pull each item out, or use compose, or individual get item?

 

Thanks in advance

Captureee.JPG

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

You can do it without any loops. The value is array, so you need to use a function that will deal with it as such. Use a select action and for the from use:

triggerBody()['Task_x0020_assigned_x0020_to']

You may have to tweak the field name. Then switch the select action to text mode and just put in:

item()['Email']

Then after the select add a compose which joins the components of the newly created array, which contains only email addresses:

join(body('Select'), ';')

Which will produce a string of email addresses, separated by semi colons. Which is what you need for your email action.

TaskAssignments.png

View solution in original post

2 REPLIES 2
tom_riha
Super User II
Super User II

Hello @somedudeWA ,

the 'Apply to each' is added automatically because the 'Task assigned to' column is set to allow multiple users. If it allows multiple selection then Power Automate must be prepared to process all the users in a loop. If you switch it to a single user column it'll not add the 'Apply to each'.

Also, the 'Apply to each' doesn't matter if you enter just a single user as the task assignee, it'll loop only through that 1 user = it'll run only once.

But if you need to send the email to multiple users at once, you can 'Initialize a variable' of a string type, then inside the 'Apply to each' use 'Append to string variable' and add each email address into the variable with ; (separator between emails) at the end. Then you could move the 'Send an email' out of the 'Apply to each' and send just a single email to users in that variable.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Paulie78
Super User III
Super User III

You can do it without any loops. The value is array, so you need to use a function that will deal with it as such. Use a select action and for the from use:

triggerBody()['Task_x0020_assigned_x0020_to']

You may have to tweak the field name. Then switch the select action to text mode and just put in:

item()['Email']

Then after the select add a compose which joins the components of the newly created array, which contains only email addresses:

join(body('Select'), ';')

Which will produce a string of email addresses, separated by semi colons. Which is what you need for your email action.

TaskAssignments.png

View solution in original post

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Users online (41,251)