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
Super User II
Super User II

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
Super User II
Super User II

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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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
Top Kudoed Authors
Users online (2,222)