Apr 4, 2020

How to read SharePoint Person or Group field in Power Automate ( MS Flow ) and Send email


Hi Guys,

This post is on a basic concept like reading the values of a SharePoint person or group field from Ms flow.  Recently i got a requirement to design a flow which reads the list item's metadata . During its design i noticed there is no direct way to read the values from the person or group field. ( at least by the time of writing this blog ). So i wanted to share the logic which i have implemented to achieve it.

Here is my requirement :

I have a field called Customers which is of type person or group with allow multiple sections . Which contains three people objects.  So in my flow i need to retrieve Customers email ids with a colon (;) separated and send an email to them.

Here is my Customers column :




Now lets design the flow to retrieve these

Here i am creating a flow with manual trigger action . The first action is Get Item



Add a Select - Data Operation activity and set From with the Customers field like below.

This Select operation takes only array as input.



Here this Customers object (Array) contains many attributes like display name, email id etc. But we are interested in getting email ids only.

So we need to map email ids object by a key value. Here my key name is keyCstmrEmailIds .
Map this key with Customers Email field like below ( make sure there is no empty space in the key )






So here is the complete Select Action :



Now using logical expressions retrieve these values.

Add a initialize a variable action and give the name of the variable as "varActualCustomerEmailIds" with type "array" and fill the Output of previous Select action. like below




Now initialize another variable of type string with name "varFinalCustomerEmailIdString" and leave its value as blank. We will use this variable to store the result email ids.





Now the varActualCustomerEmailIds  contains the CustomerEmailIds array (Output of Select Action ). Now we need to retrieve these one by one and combine then with semincolon ";".

Lets do this.

Add a Apply to each Action and add varActualCustomerEmailIds  .



Now we need to retrieve each email id from this varActualCustomerEmailIds array and concat them one by one with semi colon ";"

So add a Data Operations - Compose action and add below Expression to concat email id and semicolon.

concat(item()?['keyCstmrEmailIds'],';')





if you observe the keyCstmrEmailIds is the Key defined in above Select action . This contains output like emailId1;  
So now we need to append these result values in every loop item and store in a string variable.

Lets do that.

Add another Data Operations - Compose  action and assign Output of previous Compose action like below




And append string variable varFinalCustomerEmailIdString  to it ( So complete Compose2 action looks like below)



Now store this appended value to the same string variable varFinalCustomerEmailIdString   like below.

Add a Set Variable action and set varFinalCustomerEmailIdString  with  Output of Compose 2 action like below



DONE.  Now varFinalCustomerEmailIdString contains the email ids with ";" attached.

Lets send an email with To address as this varFinalCustomerEmailIdString  variable.




Here is the email to three customers ( From the list item Customers field ).



Hope this helps some one !

Thanks
Purna