cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PJBruen
Helper III
Helper III

Set a variable to the current screen name on a Component

Hi all,

I have a component with an icon that when clicked from the various screens, I would to set a variable value of the screen name. For some reason, this is not working.

Any ideas?

 

  PJBruen_0-1607507336597.png

So when the icon is clicked, it's just not setting the variable at all......but I'm not sure why it's an issue. If I do the same thing on a screen, it works fine.

1 ACCEPTED SOLUTION

Accepted Solutions
GarethPrisk
Resident Rockstar
Resident Rockstar

I confirmed that this function will work in a component.

However, you need to be cognizant of how components work.

  • Variables are contextually set/used per instance of the component
  • They cannot access variables set outside of themselves, unless you pass them to it
  • They cannot pass variables set inside of themselves, unless you pass them out of it
  • Components have no context of the screen/app, except what they are given
  • Components allow you to define common layouts/behaviors, but each component used in the app is a standalone instance of the component (no shared context)

What is likely happening is that your component is immediately navigating to another screen, and now you are no longer viewing that particular instance of the component. You can confirm this by commenting out the Navigate portion of the above function, and adding a label in the component. It will set the value on-click, but as soon as it navigates, you are now viewing the navigated-to screens component instance.

 

Unfortunately there's not an easy way to accomplish this (persisting variables in all components). One option is to:

  • Have an output Boolean
  • Have it set itself on click of control(s) in component Set( varClicked, !varClicked)
  • Use a Toggle on the app screen where the component exists
    • Set its Default equal to Component.OutputBooleanName
    • Set a function using the OnChange property
      • Perhaps set a global app variable here
      • This can be passed back into all components, as needed

View solution in original post

1 REPLY 1
GarethPrisk
Resident Rockstar
Resident Rockstar

I confirmed that this function will work in a component.

However, you need to be cognizant of how components work.

  • Variables are contextually set/used per instance of the component
  • They cannot access variables set outside of themselves, unless you pass them to it
  • They cannot pass variables set inside of themselves, unless you pass them out of it
  • Components have no context of the screen/app, except what they are given
  • Components allow you to define common layouts/behaviors, but each component used in the app is a standalone instance of the component (no shared context)

What is likely happening is that your component is immediately navigating to another screen, and now you are no longer viewing that particular instance of the component. You can confirm this by commenting out the Navigate portion of the above function, and adding a label in the component. It will set the value on-click, but as soon as it navigates, you are now viewing the navigated-to screens component instance.

 

Unfortunately there's not an easy way to accomplish this (persisting variables in all components). One option is to:

  • Have an output Boolean
  • Have it set itself on click of control(s) in component Set( varClicked, !varClicked)
  • Use a Toggle on the app screen where the component exists
    • Set its Default equal to Component.OutputBooleanName
    • Set a function using the OnChange property
      • Perhaps set a global app variable here
      • This can be passed back into all components, as needed

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,168)