web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Toggle OnChange event ...
Power Apps
Answered

Toggle OnChange event isn't working when app loads

(0) ShareShare
ReportReport
Posted on by 148

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?

Categories:
  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    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 

  • AaronRichardson Profile Picture
    148 on at

    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. 

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @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.

     

     

  • AaronRichardson Profile Picture
    148 on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard