cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
UsermanX
New Member

How to check if user is in Azure AD group before trying to add/remove user to it?

I need to create a Form to ask user permission for something. If user answers "Allow", user object is added to Azure AD group "X" and if user chooses "Deny", user object is removed from the same group "X".

 

Ok, no problem here and this is working if user is not in the group when adding and also if user is in the group when removing. The problem is that users might use this Form many times and Power Automate fails if it tries to add user again and it also fails if it tries to remove user that is not in the group.

 

So I need a way to check if the user is in the group before and only perform actions then if needed. What is the best way to achieve this? I've googled and tried all sorts of methods, but no luck. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @UsermanX,

 

You should be able to use the Check group membership (V2) action for this. After that you could use a condition to check the output of that action. When it is empty the user is not a member of the group.

 

Below is an example of that approach.

 

length(outputs('Check_group_membership_(V2)')?['body/value'])

 

checkgroupmembershipv2.png

View solution in original post

2 REPLIES 2
Expiscornovus
Super User
Super User

Hi @UsermanX,

 

You should be able to use the Check group membership (V2) action for this. After that you could use a condition to check the output of that action. When it is empty the user is not a member of the group.

 

Below is an example of that approach.

 

length(outputs('Check_group_membership_(V2)')?['body/value'])

 

checkgroupmembershipv2.png

View solution in original post

Thanks, this did the trick. I tried several other methods, but not this one.

 

I actually did not even notice that there was a dedicated action to check for group membership.

 

I also had one other problem that was making testing difficult. My Form had a slash "/" in response and that was making my switch-structure to act crazy.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,277)