Welcome back to all of my blog readers. I am back with another blog on Power Apps. In today’s blog I am going to discuss about a very simple requirement – “How to check if a user is a part of Office365 group?”.
So let’s get started. First and foremost, the Office 365 Group related functions are not in Office365Users connector. For this you have to use another connector which is Office365Groups.
You have multiple functions which all seems likely to do the job.
- ListGroupMembers
- ListGroups
- ListOwnedGroups
- ListOwnedGroupsV2
- ListOwnedGroupsV3
What you should use depends on the requirement. If you requirement is to check if the logged in user is part of a specific group, the best function to use is ListOwnedGroupsV3. This function returns not only the groups the user owns but also groups the user is part of.
The following code returns true if the logged in user is part of a group named “Contoso“.
If(
CountRows(
Filter(
Office365Groups.ListOwnedGroupsV3().value,
DisplayName = "Contoso"
)
) > 0,
true,
false
)
I have applied the filter on DisplayName property but you can even search on other properties like mail, id etc of the group.
Now the next requirement – What if the user is not the logged in user? Below is the formula to accomplish the same.
If(
CountRows(
Filter(
Office365Groups.ListGroupMembers(First(Office365Groups.ListGroups({'$filter': "displayName eq 'Contoso'"}).value).id).value,
mail = <email of the user to be compared>
)
) > 0,
true,
false
)
The ListGroupMembers function require the Id of the group as one of it’s parameters. We get the ID of the group named contoso using the formula in bold and italic.
Once we have the Id, we use the filter function to identify if the user with specified email is part of the group.
Hope this helped. You will also like the below posts.
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.