Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Reset datacards OnChange

Posted on 26 Nov 2024 06:50:19 by 99
Hi community,
 
I have below datacards
 
 
Current position ITEMS are dependent on the selection of the department as well as employment address which is dependent on the other two Datacard selections.
I want to be able to reset their values when a datacard is changed.E.g if i change department  i need current position to reset as ITEMS may be different now.The same for the employment address.
Well now i can do this if it is a New Submission.If i am editing a record though i cant get it to work as default values are always the same and it confuses the user.
 
Is there some way i can get around this?
 
Thanks
Categories:
  • Suggested answer
    jpespena Profile Picture
    jpespena 150 on 26 Nov 2024 at 11:09:58
    Reset datacards OnChange
    Hi again,
     
    To answer your question, you're right the OnChange property is being triggered when you switch your form from View to Edit mode. What you can do to prevent it from triggering is to add a validation if the value is change like this for the Department dropdown:
    If(
        Gallery.Selected.Department <> Self.Selected.Value,
        UpdateContext({locCurrentPosition: Blank(), locEmployeeAddress: Blank()})
    )
    This code looks if the selected value is not equal to the current value of the selected item in the gallery, then it perform the update context.
     
    Apply the same on the Current Position dropdown.
     
     

    If my post helped resolve your issue, please click Accept as Solution—this helps others find it more easily and marks the item as closed. If you found this or my previous reply helpful, a Like would also be appreciated!

     
  • jpespena Profile Picture
    jpespena 150 on 26 Nov 2024 at 10:49:33
    Reset datacards OnChange
    Hi,
     
    If you have a button that change the form to Edit mode, add this code to that button:
    UpdateContext({ locCurrentPosition: Gallery.Selected.CurrentPosition, locEmployeeAddress: Gallery.Selected.EmployeeAddress })
     
  • NM-06090901-0 Profile Picture
    NM-06090901-0 99 on 26 Nov 2024 at 10:19:57
    Reset datacards OnChange
    Hi @jpespena. This was my first approach but for some reason when i press the button to convert the form from view to edit the context variables that i have in  the OnChange property of Department trigger .I also noticed that if a datacard is text only the OnChange does not trigger when changing to EditForm.Can someone confirm that this is how is supposed to work?? Or is this a bug?  Does the onchange of a dropdown in a datacard trigger when i change the form from view to edit?
  • Suggested answer
    jpespena Profile Picture
    jpespena 150 on 26 Nov 2024 at 09:30:51
    Reset datacards OnChange
    Hi,
     
    Try this:
     
    If your form is on another screen and assuming your items is in a gallery, add this code on the OnVisible property of the screen:
    UpdateContext({ locCurrentPosition: Gallery.Selected.CurrentPosition, locEmployeeAddress: Gallery.Selected.EmployeeAddress })
    If it's in the same screen as your gallery, just put the code on the OnSelect property of the gallery.
     
     
    Then on your form, set the Default property of the CurrentPosition to:
    locCurrentPositon
    And EmployeeAddress Default property to:
    locEmployeeAddress
     
    Then, on the OnChange property of Department dropdown, add this:
    UpdateContext({ locCurrentPosition: Blank(), locEmployeeAddress: Blank() })
    And on OnChange property of CurrentPosition dropdown:
    UpdateContext({ locEmployeeAddress: Blank() })

    If my post helped resolve your issue, please click Accept as Solution—this helps others find it more easily and marks the item as closed. If you found this or my previous reply helpful, a Like would also be appreciated!
     
  • NM-06090901-0 Profile Picture
    NM-06090901-0 99 on 26 Nov 2024 at 08:41:20
    Reset datacards OnChange
     
    Thanks for replying .Unfortunately i dont want blanks once i click on edit.I want them to be blank if i change anything from those fields
  • Suggested answer
    mmbr1606 Profile Picture
    mmbr1606 9,852 on 26 Nov 2024 at 07:56:22
    Reset datacards OnChange
    hey
     
     
    you can set the default property of the Currentposition to:
    If(
        FormMode = FormMode.Edit,
        ThisItem.CurrentPosition,
        Blank()
    )
    
    same for adress:
    If(
        FormMode = FormMode.Edit,
        ThisItem.EmploymentAddress,
        Blank()
    )
    
    item property of position:
    Filter(CurrentPositionSource, Department = DepartmentControl.Selected.Value)
    
    and for adress:
    Filter(EmploymentAddressSource, 
        Department = DepartmentControl.Selected.Value &&
        CurrentPosition = CurrentPositionControl.Selected.Value
    )
    
     
     
     
    if that helped please mark as verified
     
     
    cheers
  • NM-06090901-0 Profile Picture
    NM-06090901-0 99 on 26 Nov 2024 at 07:48:19
    Reset datacards OnChange
    Thanks for replying!
     I am currently doing that for the new form.
    If my form is in edit form mode though reset brings them back to their original values and not blank as required
  • Suggested answer
    jpespena Profile Picture
    jpespena 150 on 26 Nov 2024 at 07:30:24
    Reset datacards OnChange
    Hi,
     
    You can add Reset() function on the OnChange property of the dropdown/combobox like:
     
    For Department dropdown:
    OnChange:
    Reset(CurrentpositionDropdown);
    Reset(EmploymentAddressDropdown);
    For Currentposition dropdown:
    OnChange:
    Reset(CurrentpositionDropdown);
     

    If my post helped resolve your issue, please click Accept as Solution—this helps others find it more easily and marks the item as closed. If you found this or my previous reply helpful, a Like would also be appreciated!

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,129

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,797

Leaderboard