SOLVED

Second "Apply to Each" inserts automatically when using People/Group field to ID email recipients

%3CLINGO-SUB%20id%3D%22lingo-sub-183951%22%20slang%3D%22en-US%22%3ESecond%20%22Apply%20to%20Each%22%20inserts%20automatically%20when%20using%20People%2FGroup%20field%20to%20ID%20email%20recipients%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-183951%22%20slang%3D%22en-US%22%3E%3CP%3EA%20business%20stakeholder%20came%20to%20me%20asking%20to%20write%20a%20Flow%20on%20a%20SP%20Custom%20List%20used%20to%20track%20tasks%20(not%20a%20Task%20List%20template).%26nbsp%3BThe%20requirements%3A%20send%20an%20email%20to%20task%20owner(s)%20if%20an%20incomplete%20task%20is%20due%20in%20two%20days%20or%20less.%20Also%2C%20only%20send%20emails%20during%20weekdays.%20Here%20is%20what%20the%20fully%20operational%20Flow%20looks%20like%2C%20with%20some%20names%2Ftitles%20redacted%20to%20protect%20privacy.%20Note%20the%20intentional%20application%20of%20'Apply%20to%20each'%20here.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20850px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F32473iD968630DF7308389%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22FunctionalFlowRedacted.png%22%20title%3D%22FunctionalFlowRedacted.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wrote%20most%20of%20the%20Flow%20with%20no%20trouble%2C%20but%20ran%20in%20to%20an%20interesting%20behavior%20with%20the%20email%20portion%20that%20I%20would%20like%20to%20focus%20on%20in%20this%20post.%20When%20I%20was%20testing%2C%20I%20had%20my%20work%20email%20address%20entered%20in%20the%20%22To%22%20line%20so%20that%20users%20would%20not%20receive%20emails%20prematurely.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20time%20came%20to%20put%20the%20finishing%20touches%20on%20the%20Flow%20and%20flip%20the%20proverbial%20switch.%20There%20is%20a%20people%20picker%20field%20in%20my%20custom%20list%20that%20contains%20the%20task%20owner's%20name%20and%20details.%20I%20cleared%20my%20email%20address%20from%20the%20%22To%22%20field%2C%20selected%20the%20Task%20Owner's%20Email%20address%2C%20and%20then%20Flow%20decided%20to%20add%20another%20Apply%20to%20Each.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20821px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F32474iD3AD75BFBB594A9B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22EmailRedacted.png%22%20title%3D%22EmailRedacted.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EFlow%20did%20this%20every%20time%20one%20of%20my%20two%20people%20picker%20fields%20(Team%20Task%20Owner%20and%20Other%20Owner)%20were%20used%20in%20the%20email%2C%20regardless%20of%20where%20in%20the%20email%20they%20were%26nbsp%3Breferenced%20(To%2C%20Subject%2C%20Body%2C%20etc.)%20I%20shrugged%20and%20thought%20nothing%20of%20it%20until%20I%20went%20to%20run%20my%20flow%20and%20received%20errors.%20Apply%20to%20each%20is%20not%20inserted%20if%20I%20use%20Created%2FModified%20By%20in%20place%20of%20the%20task%20owner%20email%20in%20the%20%22To%22%20line%2C%20but%20I%20cannot%20use%20that%20field%20in%20this%20context%20as%20that%20may%20or%20may%20not%20be%20the%20same%20as%20the%20Task%20Owner.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20get%20around%20this%20error%2Funwanted%20Apply%20to%20each%2C%20I%20did%20something%20rather%20shameful%20by%20O365%20standards.%20I%20wrote%20a%20SharePoint%20Designer%20Workflow%20to%20populate%20hidden%20fields%20with%20the%20names%20and%20emails%20for%20the%20task%20owners%20specified%20in%20the%20list%20item%2C%20then%20used%20those%20workflow-populated%20fields%20in%20my%20Flow%20email.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20help%20but%20think%20there%20should%20be%20a%20better%20way%20to%20accomplish%20this.%20I%20am%20posting%20here%20hoping%20that%20someone%20can%20steer%20me%20in%20the%20right%20direction%20and%20so%20I%20can%20suppress%20the%20urge%20to%20use%20Workflows%20to%20fill%20gaps%20that%20Flow%20leaves%2C%20perceived%20or%20otherwise.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%20Creating%20a%20column%20to%20capture%20Task%20Owner%20email%20addresses%20that%20is%20populated%20by%20Flow%20is%20not%20an%20option%20in%20this%20scenario%20because%20I%20cannot%20have%20all%20items%20shown%20as%20being%20edited%20by%20me.%20Also%2C%20users%20have%20alerts%20set%20on%20the%20list%20to%20notify%20them%20of%20updates.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-183951%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Flow%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-185842%22%20slang%3D%22en-US%22%3ERe%3A%20Second%20%22Apply%20to%20Each%22%20inserts%20automatically%20when%20using%20People%2FGroup%20field%20to%20ID%20email%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-185842%22%20slang%3D%22en-US%22%3E%3CP%3EActually%20I%20foudn%20that%20the%20join%20didn't%20work%20very%20well%20for%20me%20on%20people%20fields%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fveenstra.me.uk%2F2018%2F04%2F23%2Fmicrosoft-flow-the-pains-of-sharepoints-multi-people-fields%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fveenstra.me.uk%2F2018%2F04%2F23%2Fmicrosoft-flow-the-pains-of-sharepoints-multi-people-fields%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-185247%22%20slang%3D%22en-US%22%3ERe%3A%20Second%20%22Apply%20to%20Each%22%20inserts%20automatically%20when%20using%20People%2FGroup%20field%20to%20ID%20email%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-185247%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20is%20a%20reason%20that%20you%20are%20getting%20the%20apply%20to%20each%20step%20inserted.%20The%20email%20field%20is%20an%20array%20of%20email%20addresses.%20So%20what%20you%20should%20do%20is%20turning%20this%20array%20into%20a%20single%20piece%20of%20text%20and%20all%20will%20be%20fine.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20could%20use%20the%20join%20function%20in%20the%20expressions%20tab%20to%20sort%20this%20out.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20353px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F32670iE50BDEC71A190CB1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22joinfunction.PNG%22%20title%3D%22joinfunction.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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.

FunctionalFlowRedacted.png

 

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.

 

EmailRedacted.png

  

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.

2 Replies
Highlighted

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.

 

joinfunction.PNG

Highlighted
Best Response confirmed by Michael Pregent (Occasional Contributor)