PowerApps - Work around for "OnChange event is triggered automatically when navigate to different records in Gallery"

Issue faced in Form - Edit mode:

    My screen: I've Edit Form in "My screen", there are 3 controls. When changing the 1st control's (combo box) value, the OnChange event will be triggered where I've written the code to clear the other 2 control's value. Note: Other controls data should be cleared only when 1st control's value is changed manually by the user.

    Code written in OnChange property of 1st control:
    Code written in Default property of other 2 controls:
    Code written in OnVisible property of "My screen":

    Scenario: 
  • From gallery screen, I've opened the record (let say R2), the OnChange event in 1st control is not triggered, so other controls data is not cleared as expected. 
  • When trying to open the different record (lets say R4) for the second time, the OnChange event in 1st control is triggered and so other controls data is cleared. But in this scenario, the OnChange event code must not be executed and so other controls data must not be cleared. 
        We can't prevent the OnChange event call when the 1st control value in R2 and R4 is different. 
    
    Workaround:
  • We need to add the if condition in OnChange property of 1st control where only if the data from table is not equal to the currently selected value then perform the reset operation in other 2 controls:

                                            Or
  •     If you don't want to execute the code in Form mode: New then we can also check for Not Blank as mentioned below:


Related post from other source:

        https://powerusers.microsoft.com/t5/Building-Power-Apps/toggle-On-Change-property-triggered-at-every-FormDisplay-mode/td-p/1531511     

Comments

Popular posts from this blog

PowerApps - Filter Combo box control based on another table

PowerApps - Existing Date picker component - Current month date is not selectable