It's tricky to use Multi Select fields, could be a Choice field / People Picker. It's because the values returned in these field types are JSON Object Arrays, thus if we try to use field directly in an email action or other, it would auto add Apply to Each and extracts individual item as in below image.
And the Sample JSON is as below.
In order to use the values, we first need to extract Values from above JSON and join the values.
There are couple of ways to implement it as below
Approach 1:
If we don't want to use Parse JSON action, we can directly refer the Multi Choice field in Apply to Each. By doing so, we won't be able to select the Value property from JSON object, but can use simple expression to fetch it, item()?['Value']
Approach 2: (Suggested.)
Second approach executes much quicker compared to other as we don't use Loop action here.
And, if the field is People Picker, the JSON data sample is as below and instead of 'Value' property in above expressions, we can choose Email / DisplayName as per requirement.
And the Sample JSON is as below.
[
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
"Id": 1,
"Value": "Agriculture"
},
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
"Id": 3,
"Value": "Political"
},
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
"Id": 5,
"Value": "Engineering"
}
]
In order to use the values, we first need to extract Values from above JSON and join the values.
There are couple of ways to implement it as below
Approach 1:
- Initialize Variable of type String to hold the value
- Use Parse JSON Action to parse the JSON object data, i.e. the multi choice field
- Use Apply to Each to go through the Parsed JSON response
- Inside Loop action, add Append to String action and set the Value property of Parsed Object to created variable
- Now the variable will have selected values with semi-column separated and can be used in any action as a string.
If we don't want to use Parse JSON action, we can directly refer the Multi Choice field in Apply to Each. By doing so, we won't be able to select the Value property from JSON object, but can use simple expression to fetch it, item()?['Value']
Approach 2: (Suggested.)
- Use Select action to select Value property from the JSON object array, here we use expression item()?['Value']
- Use Join Action with semi column separator to join the values from above action
Second approach executes much quicker compared to other as we don't use Loop action here.
And, if the field is People Picker, the JSON data sample is as below and instead of 'Value' property in above expressions, we can choose Email / DisplayName as per requirement.
[
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|demo1@sptest.onmicrosoft.com",
"DisplayName": "LaxmiNarayana Ruttala",
"Email": "demo1@sptest.onmicrosoft.com",
"Picture": "https://sptest.sharepoint.com/_layouts/15/UserPhoto.aspx?Size=L&AccountName=demo1@sptest.onmicrosoft.com",
"Department": null,
"JobTitle": null
},
{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|demo2@sptest.onmicrosoft.com",
"DisplayName": "Demo User",
"Email": "demo2@sptest.onmicrosoft.com",
"Picture": "https://sptest.sharepoint.com/_layouts/15/UserPhoto.aspx?Size=L&AccountName=demo2@sptest.onmicrosoft.com",
"Department": null,
"JobTitle": null
}
]