Background:
I have a list in which there are fields having data types “Person or Group”, mostly I’m storing groups in it and the group can be different for each row. I needed user emails associated with a SharePoint group to send emails, but when you pass a group value in Email Recipient it gives an error which says email value cannot be null. Basically, the groups do not have any email associated with it but the groups store users’ detail which includes User Emails. So, to get those Email, we need to pass group ID in “Send an Http request to SharePoint” action. But there is no built-in action in power automate to get group ID. Below is the solution I found to get Group ID by passing SharePoint Group Display name.
Solution:
Following are the steps you need to follow:
- I’ve created a flow which triggers with “When a HTTP request is Received” which receives groupname as input parameter because I needed to get group id at multiple stages in different flows. You can get groupname simply from any field having data type “Person or Group” by selected the property with Display name. For Example: I have a column named as Finance with data type “Person or Group” So I’ll pass “Finance DisplayName” property which will have the group name of group assigned in it.
2. Add an action “Send an HTTP request to SharePoint” and pass the following values, Please note that in Uri I’m passing _api/web/sitegroups to get all the groups associated with this site.
3. Add a Filter array action and in From write the following code in expression:
outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['d']?['results']
and pass groupname input parameter at right side and write following code at the left side of comparison.
item()?['Title']
4. After that you can add a compose in which you can pass the following code to get the ID of group.
body('Filter_array')?[0]['Id']
5. Then you can simple pass this GroupID in “When a HTTP request is Received” and get users details.
6. Add a Select action to only get the emails of users. Select the icon in front of Map to convert it into one column instead of two columns. Write following code in expression in From and Map in expression.
outputs('Send_an_HTTP_request_to_SharePoint_2')?['body']?['d']?['results']// From
item()?['Email'] //Map Code
7. Add another compose to join the emails because you will get an array of emails as a response from Select action. Write Code in expression :
join(body('Select'),';')
8. Then I’m passing it as a response to the calling flow.
9. In the calling flow following are the actions you need to add.
Set the response in a variable/compose by writing the following code in expression :
body('HTTP_3')?['GroupUserEmail']
For the steps 5,6 and 7 , I would like to thank Reza Dorrani for his video on Power
Comments