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

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

ON/OFF - Toggle state, change status via OnChange formula

(0) ShareShare
ReportReport
Posted on by 16

Hello,

 

I'm looking for a solution for,

 

wanted action:

OnChange = IF(My.Value=true, ……then Toggle State turn ON…. , false)


I have the same question (0)
  • Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at
    Re: ON/OFF - Toggle state, change status via OnChange formula

    Hi @I_need_help,

     

    The best way to handle states would be via variables. You can set a variable in the OnStart of the app, or if it's literally a toggle you're meaning, set it during the OnVisible of the page the toggle is on. You can then link the variable name wherever you need it (such as the Default definition of the toggle) and set your code to 

    OnChange = IF(My.Value=true,Set(MyVariableName,true), Set(MyVariableName,false))

  • I_need_help Profile Picture
    16 on at
    Re: ON/OFF - Toggle state, change status via OnChange formula

    Hello Sickle Cell,


    thank you for your message.

    To make the app more user friendly, there is a scenario where I want to use a function that triggers the "mouse click-click" toggle via formula logic without the user doing so.

    The switch should be changed from “false” to “true” or vice versa via a formula event.
    I think I would have to change the "Toggle.Default.Value" to do this. But I don't know a suitable formula.


  • Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at
    Re: ON/OFF - Toggle state, change status via OnChange formula

    Hi @I_need_help,

     

    Yeah, a variable is definitely the way to go. You would set the Toggle Default value as a variable (such as varName for example), then you can either Set a variable(if you want it as a global, and you can do this during the App OnStart) or use UpdateContext. In this instance, UpdateContext is likely better, as you can use the code of UpdateContext({varName:!varName}) which would swap the toggle as on or off every time the user triggers whatever function you attach that code too.

    Can you give an example of your specific use case? If so, I can possibly tailor it more 

  • Verified answer
    JasonZF Profile Picture
    572 on at
    Re: ON/OFF - Toggle state, change status via OnChange formula

    So you want a toggle to change back and forth only if another value is true? If My.Value is true, then clicking this button will endlessly cycle varToggleState back and forth from true to false. The sets the variable to the opposite of what it currently is.

    If(
    	My.Value,
    	Set(varToggleState,!varToggleState)
    )

      

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 686 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 433 Super User 2025 Season 2

#3
wolenberg_ Profile Picture

wolenberg_ 266 Moderator

Last 30 days Overall leaderboard