web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Button visible on star...
Power Apps
Answered

Button visible on start and if member of a group

(0) ShareShare
ReportReport
Posted on by 394 Super User 2024 Season 1

Dear All,

 

I have the following code which is on visible part of the button, but when the screen loads it shows them and the hides. Ideally I want them only shown if person is a member of a group and by default invisible on start, can you help?

 

Thanks

 

Daniel

 

If(
CountRows(
Filter(
Office365Groups.ListGroupMembers("Group ID").value,
Lower(mail) = Lower(User().Email)
)
) <> 0,
true,
false
)

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    Hey,

     

    Just to get u right, u have a button and this button should only be visible for a certain group of people right?

     

    This is what i did in one of my apps:

    Put this variable in the Onvisible of your first screen

    Set( 

        varIsOwner, 

        User().Email in 'Office365-Gruppen'.ListGroupMembers("INSERT YOUR GROUP ID HERE").value.mail 

    ); 

     

    In the Visible property of your button just put varIsOwner.

     

     

    Please accept as Solution if it helped

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    So I want a button visible if a person is a member of a group in office 365. the above doesnt seem to work?

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    I had german as language in this solution so u might try:

     

    mmbr1606_0-1701183181487.png

    i did a test and it worked. Did you make sure,that u have the Office365 connector connected? My above suggestion was when i had german as language (thats why it did not work on your side). The new suggestion should be good to go

  • Hassan_SZ_365 Profile Picture
    542 on at

    Hello @DLCaterhamSch ,

     

    To ensure the button is invisible by default and only becomes visible if the user is a member of the specified group, you can adjust the visibility property of the button. Here's a revised version of your code:

     

    VarIsMemberOfGroup = false;
    If(
     CountRows(
     Filter(
     Office365Groups.ListGroupMembers("Group ID").value,
     Lower(mail) = Lower(User().Email)
     )
     ) > 0,
     Set(VarIsMemberOfGroup, true)
    );
    VarIsMemberOfGroup

     

    Steps to follow:

    1. At the screen's OnVisible property, place the code above. This initializes a variable VarIsMemberOfGroup to false and then checks if the user is a member of the group. If they are, it sets VarIsMemberOfGroup to true.

    2. Set the Visible property of the button to VarIsMemberOfGroup.

    This approach ensures that the button's visibility is determined when the screen loads, based on the group membership, and remains consistent throughout the session.

     

    Best Regards,

    Hassan Raza

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    If I wanted to copy the code you say twice as I need to do this again for another item with different group how do i do it i.e, this causes errors:

    VarOnbehalf = false;
    If(
    CountRows(
    Filter(
    Office365Groups.ListGroupMembers("Group 2").value,
    Lower(mail) = Lower(User().Email)
    )
    ) > 0,
    Set(VarOnbehalf, true)
    );
    VarOnbehalf


    VarHideShowHolidayCateringRequest = false;
    If(
    CountRows(
    Filter(
    Office365Groups.ListGroupMembers("Group 1").value,
    Lower(mail) = Lower(User().Email)
    )
    ) > 0,
    Set(VarHideShowHolidayCateringRequest, true)
    );
    VarHideShowHolidayCateringRequest

  • Verified answer
    Hassan_SZ_365 Profile Picture
    542 on at

    Hi @DLCaterhamSch ,

     

    Use this Formula:

     

    // Initialize both variables to false
    Set(VarOnbehalf, false);
    Set(VarHideShowHolidayCateringRequest, false);
    
    // Check membership for Group 2
    If(
     CountRows(
     Filter(
     Office365Groups.ListGroupMembers("Group 2").value,
     Lower(mail) = Lower(User().Email)
     )
     ) > 0,
     Set(VarOnbehalf, true)
    );
    
    // Check membership for Group 1
    If(
     CountRows(
     Filter(
     Office365Groups.ListGroupMembers("Group 1").value,
     Lower(mail) = Lower(User().Email)
     )
     ) > 0,
     Set(VarHideShowHolidayCateringRequest, true)
    );
    
    // You can now use VarOnbehalf and VarHideShowHolidayCateringRequest to control visibility or other properties

     

    lace this code in the OnVisible property of the screen where you want these checks to occur. This code initializes two separate variables, VarOnbehalf and VarHideShowHolidayCateringRequest, to false. It then checks the membership of the current user in "Group 2" and "Group 1" respectively, setting the variables to true if the user is a member.

    You can then use these variables (VarOnbehalf and VarHideShowHolidayCateringRequest) to control the visibility of different UI elements based on the group membership.

    Remember to replace "Group 1" and "Group 2" with the actual IDs of your groups.

    Best Regards,

    Hassan Raza

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    This seems to error? 

  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    Just copy the thing i wrote u and put the other ID of the group you need.

    Give the variable a different name and put it in the other visible property u want to show/hide.

     

    i never had any issues using it thru the entire session and all my screens/controlls.

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    I got the ID wrong and now corrected sorry and thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard