Apr 17 2018 03:07 PM - edited Apr 18 2018 12:43 PM
A business stakeholder came to me asking to write a Flow on a SP Custom List used to track tasks (not a Task List template). The requirements: send an email to task owner(s) if an incomplete task is due in two days or less. Also, only send emails during weekdays. Here is what the fully operational Flow looks like, with some names/titles redacted to protect privacy. Note the intentional application of 'Apply to each' here.
I wrote most of the Flow with no trouble, but ran in to an interesting behavior with the email portion that I would like to focus on in this post. When I was testing, I had my work email address entered in the "To" line so that users would not receive emails prematurely.
The time came to put the finishing touches on the Flow and flip the proverbial switch. There is a people picker field in my custom list that contains the task owner's name and details. I cleared my email address from the "To" field, selected the Task Owner's Email address, and then Flow decided to add another Apply to Each.
Flow did this every time one of my two people picker fields (Team Task Owner and Other Owner) were used in the email, regardless of where in the email they were referenced (To, Subject, Body, etc.) I shrugged and thought nothing of it until I went to run my flow and received errors. Apply to each is not inserted if I use Created/Modified By in place of the task owner email in the "To" line, but I cannot use that field in this context as that may or may not be the same as the Task Owner.
To get around this error/unwanted Apply to each, I did something rather shameful by O365 standards. I wrote a SharePoint Designer Workflow to populate hidden fields with the names and emails for the task owners specified in the list item, then used those workflow-populated fields in my Flow email.
I can't help but think there should be a better way to accomplish this. I am posting here hoping that someone can steer me in the right direction and so I can suppress the urge to use Workflows to fill gaps that Flow leaves, perceived or otherwise.
Note: Creating a column to capture Task Owner email addresses that is populated by Flow is not an option in this scenario because I cannot have all items shown as being edited by me. Also, users have alerts set on the list to notify them of updates.
Apr 20 2018 07:23 AM
There is a reason that you are getting the apply to each step inserted. The email field is an array of email addresses. So what you should do is turning this array into a single piece of text and all will be fine.
You could use the join function in the expressions tab to sort this out.
Apr 23 2018 01:58 AM - edited May 08 2024 01:07 AM
SolutionActually I foudn that the join didn't work very well for me on people fields:
Jul 02 2021 11:44 AM
@Michael Pregent I know this is an old post but I was trying to resolve the same issue myself today. I had one flow that worked perfectly and one based on a different SharePoint list that kept adding "Apply to Each". I compared the properties of the Person field from the two different lists and realized that in the one with the issue, "People and Groups" was selected. The one that worked correctly had "People Only". As soon as I changed that setting and tried to create the flow again, the "Apply to Each" issue went away.
Apr 23 2018 01:58 AM - edited May 08 2024 01:07 AM
SolutionActually I foudn that the join didn't work very well for me on people fields: