“I have a SharePoint column with multiple choices enabled, how can I convert the data from it (array) into a string to send it in a single email in Power Automate?”
Power Automate will automatically add ‘Apply to each’ once you try to use dynamic content from an array. It’s fine if you want to process the items one by one, e.g. update multiple items or send multiple emails. But it’s not so good if you need all the items at once. If you’ve got a SharePoint column with multiple choices, you don’t want to loop through them. You want all of the choices at once, a single string in readable format. It can be user information (emails, names), choices, lookups… The usage is the same: don’t loop, convert the values to a single string.
Simple array
If it’s a simple array with a list of values (no object structure), you can use the join(…) expression. You can see an example of simple array below (created when exporting multiple Person or Group column to .csv):
[
"xxx@tomriha.com",
"yyy@tomriha.com"
]
The join(…) expression expects 2 parameters, the array with values, and a separator for the outcome.
join([array], '[separator]')
The example below will take the array (variable var_array), and convert into a comma separated string.
join(variables('var_array'), ', ')
Notes:
variables('var_array') is the array
', ' is definition of the separator, separator are the characters between ' and '
result:
xxx@tomriha.com, yyy@tomriha.com
Array with objects
It gets a bit more complicated with more complex arrays: Person or Group column, choice column, etc. Instead of just a list of values, complex arrays contain objects with multiple pairs of “key”: “value”.
"Person_MultipleSelection": [
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|xxx@tomriha.com",
"DisplayName": "Tomáš Říha",
"Email": "xxx@tomriha.com",
"Picture": "..."
},
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|yyy@tomriha.com",
"DisplayName": "yyy@tomriha.com",
"Email": "yyy@tomriha.com",
"Picture": "..."
}
]
Join(…) expression won’t work here as it would create a string from the whole objects. And you don’t want the whole object, you want just a specific value from that array, e.g. Email.
‘Select’ the values
The best approach is to use the ‘Select’ action. The action expects an array of objects on the input, e.g. the array with multiple users, and allows you to select only some values from it. Put the array as the input, in this example it’s the ‘Person_MultipleSelection’ dynamic content. Since you want to build a string only from the values, you should ignore the key/value mapping and switch to the text mode. That way you can skip the key and select only the values.
Each object in the array is represented by the expression item(), and each value by adding ?[‘Key’]. You can use any ‘Key’ from the object. The expressions below will give you all display names or emails of the users.
item()?['DisplayName']
or
item()?['Email']
Output of the ‘Select’ action will be a new array, this time a simple one, that will contain only the desired values.
And as was already explained, a simple array can be converted into a string with the join(…) expression
join(body('Select'),';')
->
xxx@tomriha.com;no-reply@tomriha.com
Summary
When you convert an array into a string in Power Automate, the first thing to consider is: “what type of array do I need to process”? If it’s a simple array, you can use the join(…) expression. But if it’s a complex array with objects, it’ll require a ‘Select’ action first.
It’s possible to process complex arrays in a single action with a combination of expressions (as when exporting to .csv), but I believe this step-by-step approach has it’s benefits. You can track what’s happening in each step, it’s easier to debug, and much easier to explain and understand.
Hi
I’m stuck on the select values for complex arrays. I may be doing something wrong as after switching to text it doesn’t accept the expression item()?… any suggestion? Can you elaborate a bit more on that step?
Thanks a lot
All sorted
Muchas gracias desde Mexico!
I’m having an issue with multiple selections when using this flow. It works fine with one person, but when I add additional people it fails.
“The specified user Name1, Name;Name2, Name could not be found.”
Any suggestions?
Hello Kara,
it seems you’re using the string in an action that allows for only a single value. In such situations you must loop through the array and input the values one by one.
I’m after a path to a sharepoint library (which can change), I thought I’d use List Folder > Filter Array > Select. Which gives me a one item array. I should then use Join to turn it into a string? I guess my problem is I don’t actually have anything to join or a separator?
I think I’m over complicating things. Any help is appreciated.
This is a great site, thank you very much.
I guess I just needed the Rubber Duck to talk it out with:
Used Filter>Select>Compose with join(body(‘Select’),”) which seems to give me what I needed. In any case, wouldn’t have gotten there without this site. Thanks!
Hi Tom – Thanks a ton for this post. I’ve been spending sooo much time appending to array/string variables and I knew there had to be a better way. Your explanation is crystal clear and actually makes it look so simple that now I feel embarrassed not to have worked it out sooner…
THANK YOU! 🙂
I’m also not sure if Join is working correctly to where a string is outputted. As mentioned, I used a semicolon as the separator parameter, but the output shows a comma separator. For your awareness, the Join output looks just like the output of the previous step where I used Select due to a complex array. Example of the output of Join (notice the comma separator is shown):
[“Email 1” , “Email 2”]
Hello Leah,
your output is an array (the opening and closing [ ] ), it’s not a string. I’d double check the dynamic content that you apply the join(…) to.
Excellent 🙂
Yes, this is a great and straightforward solution. Thank you
WOW, this is exactly what I was looking for!!!! Even for the emails. Thanks-you so much!
This helped me out a lot!