Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Select a button that is within a component

Like (2) ShareShare
ReportReport
Posted on 12 May 2023 07:59:31 by 183

Hello πŸ™‚

 

Here is a new issue I'm facing...

I'm trying to add an access control on some screens of my app, based on a global variable.

If this variable (boolean) is false, when a user open a specific page, I want it to be redirected to the homescreen.

 

I achieved this behaviour with a button that is selected with the OnVisible() property of the screen. If the variable is false, the button is selected and the OnSelect() property navigates to the home page.

 

I want to replicate this behaviour on multiple pages so I tought I could add an hidden button on my "Navigation menu" component and select it with the OnVisible() of each pages I want to add access control on.

 

The issue is that I have no idea how to Select() a button that is in a component or if there is another way to achieve what I want witout adding a button on each page I want this access control.

 

Thank you πŸ™‚

  • crisdiglesias Profile Picture
    22 on 01 Feb 2024 at 15:37:20
    Re: Select a button that is within a component

    Hello Jedediah!

    I had a similar difficulty today and managed to resolve it using the OnReset action of the component itself.

     

    In your component's edit menu, configure OnReset to select the button that you configured as the Navigate function, but first add a Toggle to turn redirection on and off. This will ensure that your screen does not loop when you try to edit the screen:

     

    crisdiglesias_0-1706799634060.png 

     crisdiglesias_1-1706799653739.png

    crisdiglesias_2-1706799722500.png

    // OnSelect of the button inside the component
    Navigate(scn_Home;ScreenTransition.None)
    
    // OnReset of the component itself
    If(tgl_ActiveNavigate; Select(btn_NavigateTo); false)

     

     

    Now go to the screen where you will add your component and add a new button. This button will be hidden and will be responsible for selecting the component's OnReset.

     

    crisdiglesias_3-1706800339505.png

     

    Now include the Reset() function in the OnSelect of the button that will be hidden:

    crisdiglesias_5-1706801065480.png

     

    crisdiglesias_4-1706801013434.png

    Reset(cmp_scn__Navigate_To)

     

    And lastly, configure the screen's OnVisible to select the button that will be hidden:

    crisdiglesias_6-1706801128750.png

     

    -----

    This solution worked for me and I hope it works for you too! 😁

    Note: I don't speak English (I'm Brazilian) and I used Google Translate, so I ask you to disregard any writing errors πŸ˜….

  • Jedediah Profile Picture
    183 on 12 May 2023 at 15:00:43
    Re: Select a button that is within a component

    Thanks for this idea but I really want to redirect them and I can achieve this using buttons. I'm just looking for an optimized way to avoid adding buttons en each pages.

  • Adam1986 Profile Picture
    139 on 12 May 2023 at 14:35:23
    Re: Select a button that is within a component

    Maybe, add container to your restricted pages. Container will be visible if user is not permited to view screen content, it will cover full app screen. You can place in this container notification for user and homescreen navigation button. 

  • Jedediah Profile Picture
    183 on 12 May 2023 at 14:19:28
    Re: Select a button that is within a component

    The variable is initialised in OnStart() : true if the user is in a specific group, false otherwise.
    This variable is passed to the menu component to control the Visible() field of the menu items.

    So a HR member will see the HR menu, an IT member will see the IT menu, etc.

     

    With a basic usage of the app, when you access it with its URL, we have no issue since the users can't access restricted pages since they don't have a link to them in the menu.

     

    I recently added deeplinks to allow me to send link to users to specific pages. With this usage comes a little risk that a user can access pages that they can't normally access. It is this specific issue that I wan't to address.

    Since I have my variables that can tell me if the user is in a group or another, I would like to use them to add a ultimate check when sensitive pages are opened to redirect users to home page if they are not authorized to access those pages.

  • Adam1986 Profile Picture
    139 on 12 May 2023 at 12:55:47
    Re: Select a button that is within a component

    @Jedediah 

    oh, you are right. I didnt know that.
    Ok, lets try different approach then. How do plan to navigate the user to this specific screen where you want too check variable value? 

  • Jedediah Profile Picture
    183 on 12 May 2023 at 12:34:02
    Re: Select a button that is within a component

    Hello @Adam1986 πŸ™‚

    I used a button because you can't use Navigate() in OnVisible() of a screen.

  • Adam1986 Profile Picture
    139 on 12 May 2023 at 11:00:25
    Re: Select a button that is within a component

    Hi @Jedediah,

    Instead of using Button you should use OnVisible property of screen. 

    OnVisible:

    If(
     !yourBooleanVariable,
     Navigate(
     Homescreen,
     ScreenTransition.Fade
     )
    )

    So, if user opens specific screen, OnVisible of this screen will run and check if yourBooleanVariable is equal to false (notice there is !yourBooleanVariable). Then if this statement is true it will navigate user to homescreen. If yourBooleanVariable is equal to true i will do nothing.

     

    Never use Select() to run something under other component. There is always easier way.

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473