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 / Combobox OnChange fire...
Power Apps
Unanswered

Combobox OnChange fires & loops unexpectedly when selecting

(0) ShareShare
ReportReport
Posted on by 2

Hello

 

This topic has come up quite a bit, but any of the solutions haven't worked. 

 

I have a gallery with a combobox, the user can selected a value, and I want to save the ID from the selected value to a local collection. When I do that, it patches shortly, before the combobox triggers the onchange again and removes the value. 

 

Here's the code I'm using: 

OnChange:

 

 

If(
 locAllowEdit = true,
 Patch(
 colNewProjectMeasurepoints1,
 ThisItem,
 {MeasurepointIDPatched: Self.Selected.ID}
 );
 Trace("OnChange")
)

 

 

OnSelect: 

 

 

UpdateContext({
 locAllowEdit: !locAllowEdit
})

 

 

 

DefaultSelectedItems: 

 

 

LookUp(Measurepoints, ThisItem.MeasurepointID = ID)

 

 

 

The onSelect code prevents the combobox from starting a loop, but technically it should ignore the Patch statement, yet it doesn't. Anyone got any ideas? 

Categories:
I have the same question (0)
  • Adrian_Celis Profile Picture
    1,652 Moderator on at

    Hi @brownietitan 

    You should reset the locAllowEdit variable to false in your OnChange.

    So can you change your code to:

    OnSelect

    UpdateContext({locAllowEdit: true})

    OnChange

    If(
     locAllowEdit = true,
     Patch(
     colNewProjectMeasurepoints1,
     ThisItem,
     {MeasurepointIDPatched: Self.Selected.ID}
     );
     UpdateContext({locAllowEdit: false})
     Trace("OnChange")
    )

     

    This is similar to the use-case below. See the step 6 OnChange and OnSelect property of this tutorial. As you can see they are resetting the IsSelected variable:

    Power Apps – Rearrange gallery items using dropdown 

  • brownietitan Profile Picture
    2 on at

    That doesn't seem to work, it patches the data to the collection for a brief second, and then it gets reset again. 

     

    It seems that the internal component still fires the onChange completely, even though it shouldn't.

     

  • Suggested answer
    DF-27021330-0 Profile Picture
    6 on at
    I hope this is able to bless someone's day! It was nerve racking for me! hahah. 😂
     
    After the entire week of just sitting here playing with the ONE combo box, with no help from online, I think it would be good for me to post my solution here for the next person.
     
    I am working with items = Office365Users combobox with onchange patch and a conflict with defaultselecteditems. It was entering a never ending circular loop.
     
    my application screenshot:
     
    FULL EXPLANATION BELOW!
     
    my application screenshot:
     
     
    APP ONSTART CODE (be sure to "run" onstart):
    // ~~~~~~~~~~~~~~~~~ SET VARIABLES TO ALLOW DEFAULT VALUES ~~~~~~~~~~~~~~~~~ ||
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ||
    Set(varPatch, 0); // ~~~~~~~~~ IS THE PATCH PERMITTED ON STARUP? NO! ~~~~~~~ ||
    Set(varRunning, 0); // ~~~~~~~ IS THE PATCH RUNNING ON STARTUP? NO! ~~~~~~~~ ||
    Set(varStartup, 1); // ~~~~~~~ DID THE APP JUST STARTUP? YES! ~~~~~~~~~~~~~~ ||
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ||
    Set(varSpinner, false);
     
     
    COMBO BOX ITEMS:
    Filter(
        Office365Users.SearchUserV2({searchTerm:Trim(Self.SearchText), isSearchTermRequired:(false)}).value,
        !IsBlank(Mail) && EndsWith(Mail, "@youremail.com")
    )
     
     
    COMBO BOX DEFAULTSELECTEDITEMS:
    IfError(Split(ThisItem.manager_name, ","), [])
     
     
    COMBO BOX DISPLAYMODE:
    If(varRunning = 1 && varStartup = 0, DisplayMode.Disabled, DisplayMode.Edit)
    // ~~~~~~~ IF "RUNNING", BUT APP NOT ON "STARTUP" THEN "DISPLAYMODE" = DISABLED WHILE "RUNNING".
    // ~~~~~~~ IF APP IS ON "STARTUP", THEN BE SURE TO ALLOW "DISPLAYMODE" = EDIT.
     
     
    COMBO BOX ONSELECT:
    Set(varPatch, 1); // ~~~~~~~~~~~ IS ALLOWED TO ENTER "ONCHANGE" TO "PATCH" TO DATAVERSE? IF THEY SELECT, THEN YES!
    Set(varStartup, 0); // ~~~~~~~~~ IF USER SELECTS THIS FIELD, THEN THE "STARTUP" DISPLAYMODE WILL BE TURNED OFF. SET VALUE TO ZERO (0).
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STARTUP = 1 IS ONLY ASSIGNED IN THE APP'S ONSTART FUNCTION TO ENSURE "DISPLAYMODE" IS NOT DISABLED ON "STARTUP".
     
     
    COMBO BOX ONCHANGE:
    /*****************************************************************************************************|
    CMB DEFAULTSELECTEDITEMS *****************************************************************************|
        • REVERSE THE "CONCAT" PATCH ("ONCHANGE") WITH "SPLIT" TO CONVERT STRING TO TABLE.
        • THIS VALUE WILL BE ASSIGNED DURING "ONSTART" AND "ONCHANGE".
    /*****************************************************************************************************|
    APP ONSTART ******************************************************************************************|
        • VARIABLES REQUIRED TO MITIGATE FOREVER ONCHANGE/DEFAULT VALUES IN CIRCLULAR REF LOOP.
        • ON STARTUP, THE PATCH PROCESS IS NOT "RUNNING" (0) NOR ALLOWED TO RUN.
        • ON STARTUP, THE APP IS NOT ALLOWED TO "PATCH" (0) VIA "ONCHANGE" FUNCTION.
        • ON STARTUP, THE APP IS ON "STARTUP" (1) ALLOW "DISPLAYMODE" TO BE EDITED.
    /*****************************************************************************************************|
    CMB DISPLAYMODE **************************************************************************************|
        • IF "RUNNING" (1) ANNNND NOT "STARTUP" (0) THEN "DISPLAYMODE" = DISABLED
            • ELSE "DISPLAYMODE" = EDIT
        • THEREFORE, IF PATCH IS "RUNNING", DO NOT ALLOW COMBOBOX INTERACTIONS, BUT
            • DEFAULT THE "DISPLAYMODE" = EDIT ON "STARTUP" OF THE APPLICATION.
    /*****************************************************************************************************|
    CMB ONSELECT *****************************************************************************************|
        • IF USER SELECTS THIS FIELD, THEN THIS IS EVIDENCE THAT "STARTUP" IS COMPLETE. SET TO ZERO (0).
            • STARTUP VALUE WILL NOT BE SET TO ONE AGAIN UNTIL APPLICATION IS RESTARTED.
            • WITH THE "ONSELECT" AND "DISPLAYMODE" LOGIC, THIS WILL ENSURE USERS CANNOT EDIT MULTIPLE ROWS SIMULTANEOUSLY.
        • IF USER SELECTS THIS FIELD, THEN ALLOW "ONCHANGE" PATCH, THUS SETTING "PATCH" TO ONE (1).
    /*****************************************************************************************************|
    CMB ONCHANGE *****************************************************************************************|
        • IF ALLOWED TO "PATCH" (1) THEN SET "RUNNING" TO ONE (1).
            • "RUNNING" SET TO ONE (1) WILL PREVENT EDITING DURING PATCH UPDATE. "DISPLAYMODE" = DISABLE.
        • IF ALLOWED TO "PATCH" (1) THEN EXECUTE "PATCH" AND WRITE TO DATAVERSE TABLE.
        • AFTER PATCH FUNCTION IS COMPLETE, THEN RESET "PATCH" AND "RUNNING" TO ZERO (0) TO PREVENT FOREVER CIRCULAR REF LOOP.
            • THIS WILL PREVENT THE "DEFAULTSELECTEDITEMS" FROM BEING REASSIGNED TO THE ENTIRE COLUMN (FOREVER CIRCULAR LOOP).
    /*****************************************************************************************************|
    ******************************************************************************************************/
    Notify(ThisItem.KEY_CST); // ~~~~~~~~~~~~~~~~~ TO TROUBLESHOOT CURRENT POINTER! YOU CAN SEE THE LOOP TRYING TO REENTER.
     
    If(varPatch = 1, // ~~~~~~~~~~~~~~~ IS THE PROCESS PERMITTED TO PATCH THE ROW? ~~~~~~~~~~~~~ || YES, LET'S PROCESS THE PATCH.
        Set(varRunning, 1); // ~~~~~~~~~~ IS THE PROCESS RUNNING? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ || YES, THE PROCESS IS RUNNING. THEREFORE, LOCK THE APP (DISPLAY MODE).
        Patch(_iat_config_customers, LookUp(_iat_config_customers, KEY_CST = ThisItem.KEY_CST), {manager_name: Concat(cst_table_cmb_manager_classic.SelectedItems, ThisRecord.DisplayName, ",")});
    ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ||
    Set(varPatch, 0); // ~~~~~~~~~~~~~~ NO MORE PROCESSING IS PERMITTED. ~~~~~~~~~~~~~~~~~~~~~~~ ||
    Set(varRunning, 0); // ~~~~~~~~~~~~~~ THE PROCESS HAS FINISHED RUNNING. ~~~~~~~~~~~~~~~~~~~~~~ ||
     
     
  • Suggested answer
    DF-27021330-0 Profile Picture
    6 on at
    To complement my other suggested answer, I ended up having to take a different approach to speed up processing:
     
    Dataflows to push data changes to dataverse (and bypass the infinite loop).
     
     
    the patch variables are sent to a timer (do while < 16hours) loop to verify that the data is pushed. I am refreshing the other screens through this timer loop since pushing to data verse does not automatically update the frontend (while the patch does update the cache).
     

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
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard