I have a toggle on a screen (screen B, this is not the first screen in the app) that uses a global variable as the default and has some functions in the OnChange event:
Then in App OnStart I set that variable:
The toggle does not run the OnChange event when I open the published app. If I move the toggle to the first screen in the app, the OnChange runs correctly when the app is run. So there is something preventing it from running when it's on a different screen. Is there an app setting that's preventing it from running? I know toggles can fire events across screens because I use that functionality in other areas of my app. Any thoughts?
Solved! Go to Solution.
Yes it is. Toggles will not "fire" if they are on another screen, unless you reference them on the "calling" screen. This is by design (unfortunately).
If you place a label on your first screen and set the Text property to yourToggle.Value your scenario will work. You can make the label not visible.
You can also reference the toggle in many other ways. For example, I will sometimes set the visible property on an icon to the value of the toggle so that there is a visual indication that "data is loading" (or whatever your toggle might do).
@BrianS is correct though about the variable and, in your OnStart, there is really no reason to "Not" the current value - just set it to what you want, true or false. That formula will never execute again anyway.
I hope this is helpful for you.
I may be misunderstanding something - Boolean variables start out as false, so if you run that command in the OnStart I believe all it will do is set it to true when the app starts. Since this is the first mention of that variable, however, it may not trigger an OnChange event. If you want the command you show to run when the app starts why not just put it in the OnStart and then let the toggle trigger it on subsequent changes of the toggle. If you can provide a little more info, maybe we can help further
Yeah, I considered that. But like I mentioned, when I move the toggle to the first screen in the app (the one that loads first) the toggle works as intended. So it's really something about it being on a different screen that's causing the issue.
Yes it is. Toggles will not "fire" if they are on another screen, unless you reference them on the "calling" screen. This is by design (unfortunately).
If you place a label on your first screen and set the Text property to yourToggle.Value your scenario will work. You can make the label not visible.
You can also reference the toggle in many other ways. For example, I will sometimes set the visible property on an icon to the value of the toggle so that there is a visual indication that "data is loading" (or whatever your toggle might do).
@BrianS is correct though about the variable and, in your OnStart, there is really no reason to "Not" the current value - just set it to what you want, true or false. That formula will never execute again anyway.
I hope this is helpful for you.
Ah, poop. I was hoping this wasn't a "by design" type of deal.
I tried your suggested workaround and it does indeed work, so thanks a lot for that!
I appreciate the feedback on the OnStart variable. I tend to use that so that during development I can run OnStart as many times as I need to and still trigger my toggle actions, but I agree that in a published app that's not necessary. If there's no overhead in keeping that structure I'll likely continue to use that format.
Thank you for the help @RandyHayes!
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
200 | |
178 | |
67 | |
36 | |
33 |
User | Count |
---|---|
341 | |
272 | |
115 | |
73 | |
58 |