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

Toggle OnChange event isn't working when app loads

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:

AaronRichardson_0-1598372972090.pngAaronRichardson_1-1598372998761.png

 

Then in App OnStart I set that variable:

AaronRichardson_2-1598373088561.png

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions

@AaronRichardson 

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.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

4 REPLIES 4
Responsive Resident
Responsive Resident

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. 

@AaronRichardson 

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.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

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!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (10,914)