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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Toggle OnCheck propert...
Power Apps
Suggested Answer

Toggle OnCheck property is undesireable triggered by refresh() function

(1) ShareShare
ReportReport
Posted on by 413
Hi there. 
 
I have a toggle inside a gallery, used to change a "Y/N" field in a sharepoint list. 
 
These toggles are used to describe a dispender configuration: Production linea could have more dispenser, and each dispender could have only 1 legal origin. 
 
 
Inside the "Oncheck" property of my toggle i set this code:
If(
    !IsBlank(LookUp('Tracelot - Origini dosatori'; ID = ThisItem.ID && Attivo = true));
    false; // Se l'elemento è già attivo, non fare nulla
    Set(
        varProcessing;
        true
    );;
    Set(
        varCurrentItemID;
        ThisItem.ID
    );;
    // Disattiva tutte le altre origini per questa Linea e Dosatore
    ForAll(
        Filter(
            'Tracelot - Origini dosatori';
            Linea = Radio1.Selected.Value &&
            Dosatore = Title1.Text &&
            ID <> varCurrentItemID
        );
        Patch(
            'Tracelot - Origini dosatori';
            ThisRecord;
            {Attivo: false}
        )
    );;
    // Attiva l'origine corrente
    Patch(
        'Tracelot - Origini dosatori';
        LookUp('Tracelot - Origini dosatori'; ID = varCurrentItemID);
        {Attivo: true}
    );;
    Set(
        varProcessing;
        false
    );;
    true // Mantiene il toggle attivo
)
 
The code is working, the only problem is that when I start the app or I refresh the data (not in this code), the "Oncheck" property seems to be triggered and this cause some errors. 
 
What can I do to trigger the "OnCheck" property only when I manually change the toggle status? 
 
Thanks.
Categories:
I have the same question (0)
  • Suggested answer
    Calcioscacchi Profile Picture
    413 on at
    Hi  @FLMike, 
     
    This solution seems to have troubles:

    I edit your idea adding a control:
     
    If(
        !triggerOnChecked;
        Notify("test onchecked failed");
        UpdateContext({triggerOnChecked: false});;
        If(...
    .........
    And the first time I click on the toggle it return the error, this means that it is in "false" value when OnCheck is triggered. 
    The question is: OnSelect and OnCheck: which one has the priority?
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,690 Super User 2025 Season 2 on at
    HI
     
    I am actually going to try to repro this, I totally believe you, its just.. not something I have seen before.
     
    But lets think about it like this.
     
    1) Where and when are "refreshes" caused, to make sure we cover them all.
     
    Steps to try.
    1. In the OnVisible Property of the screen you can do the following code, which will help us stop it from DOING anything even though triggered when you don't want it to be
    UpdateContext({ triggerOnChecked: false });
    2. In the OnSelect of the Toggle
    UpdateContext({ triggerOnChecked: true});
    3. Then in your OnChecked for that control wrap the code in if, so when its set to false, it will NOT trigger
     
    If(triggerOnChecked,
         UpdateContext({ triggerOnChecked: false }); // so that it doesn't trigger again right away    
        // do stuff here
    
    );
     
     
     
     
     
     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 401

#2
WarrenBelz Profile Picture

WarrenBelz 334 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 325 Super User 2025 Season 2

Last 30 days Overall leaderboard