cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PJBruen
Resolver I
Resolver I

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,776)