Saturday, February 24, 2018

Microsoft Flow | Send mail to Multiple recipients from SharePoint Person Or Group field.

Scenario: you have a SharePoint List where a field with 'Person or Group' having multiple entries is selected. you want to send a mail to all the people entered in that field. However, currently that field is not supported in Microsoft Flow.

Steps on How to get multiple Entries from 'Person or Group' field in SharePoint List and send a single mail to them. 

In This example, I have a simple SharePoint List for Training Registration. Where in the Attendees field multiple people can be selected based on the Nominations. So below we have a field 'Attendees' as 'Person or Group' where 'Allow Multiple Selections:' is selected as "Yes"

  1. I am Triggering MS Flow when a new item is created in the Training Registration SPO List. 
  2. Next Step adding 'Get Item' action and fetching the item created via its 'ID'
  3. Next Step adding 'Data operations - Select' action. (this will take only an Array value as input)
    1. as the output of 'Get Item' will be an array, but I need only the attendees from that New Item created, in 'Select' Action 'From' (input for select) will be the 'Attendees' Field. 
    2. Map Key 'Attendees' to Value 'Attendees Email' (as only email can be used to send a mail.)
  4. Next we will use 'Initialize Variable' action. I named it as 'OriginalArrayAttendees'. Type as 'Array' and Value will be the Output from previous 'Select' action, we get only the Attendees Mail address in the array variable. 
  5. Next we will again use 'Initialize Variable' action. I name it as 'FinalStringAttendees'. Type as 'String' and Value as blank at this stage. 

Now we need to put all the Email addresses into a single variable separated by semi-colon (;) 
  1. Next Step -> Add 'Apply to each' where the output of variable 'OriginalArrayAttendees' is entered. 
  2. from that array, we need to concat all the email addresses with a semi-colon, so we add a 'Data operations - Compose' action and in expression enter "concat(item()?['Attendees'],';')". Pls. Note: Attendees in the concate is the 'Map Key' you gave in the above 'Select' action.
  3. Next step, we need to append the values in a single String variable which is 'FinalStringAttendees'. Pls. Note: If you do not see the variable in 'Dynamic Content', select 'Expression' and type " variables('FinalstringArray') " [ without double quotes] 
  4. Finally use 'Set Variable' action to get the concatenated string of all email addresses in variable so that it can be used out of the 'Apply to each' loop. Value of 'FinalStringAttendees' will be Output of 'Compose 2' action where we are appending all the values. 

Final step is send a Mail. using 'Send an email' action of O365 account. In the "TO" field it will be the 'FinalStringAttendees' variable. Rest of the body you can enter the way you want.


JP said...

Great post! Thanks for this solution!

There's a small error in your text (and in expression enter "concat(item()?['Attendees'])".))

You didn't mentioned the semicolon here. So the code should be "concat(item()?['Attendees'],';')"

Parmi said...

Thanks a lot JP for highlighting the correction. It is edited now :)


Google user said...

Great post, thank you for the solution.

I cannot seem to complete this step: "Next step, we need to append the values in a single String variable which is 'FinalStringAttendees'".

As we left the value as blank in the "InitializeFinalStringAttendees" step, I am unable to get the "FinalStringAttendees" dynamic content in Compose 2.

Am I missing a step to append the values in a single string variable?

Parmi said...

Thank you.

for first time finalString value will be blank. is it failing for you at any step? when you Initialize the variable, it should be kept blank. in the 2nd loop iteration, Finalstring value will have a value and it will append the next value in 'compose 2' step

Google user said...

Thanks for your response.

I have completed all the steps in the same way shown, however FinalStringAttendees is not appearing as a variable in Compose 2. I only see Output from Select and Compose 1.

Parmi said...

Now I see, you must be facing the same issue I see after Microsoft added the 'See more' functionality. you will not see the Global variable in dynamic content, you will have to use expression and add [ variables('finalstringarray') ] "without boxes". please check this thread I had with MS.

Unknown said...

Hi Parmi,

Thank you for this post, it is detailed and very helpful.

But I am having problem in "Next Step adding 'Data operations - Select' action. (this will take only an Array value as input)". SharePoint automatically adds "Apply to each" clause when I add "Attendees" in "From" field. How do I either make it not add this clause or a way to get rid of that clause there? Thanks for your help.

Here is what I am trying to do: there are 3 different fields (a,b,c) that can take multiple email values. I want to be able to concatenate each field value and send it an email. Right now, because of "apply to each" it sends aXbXc emails :)

Parmi said...

Hello there,

you cannot remove the 'Apply for each' loop as Flow will add it always for an array variable. for your requirement, you will have to create 3 Array variables and 3 finalstring variables for each a,b and c. for all 3 of them you have to first concat the email addresses in their own finalstring variable. before sending the mail. concat all the 3 finalstring variables.

you can have all 3 of them done in Parallel mode. there is option in flow to run actions in Parallel.

hope it helps. good luck

Total Pageviews