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 / Creating undo function...
Power Apps
Unanswered

Creating undo function using Patch()

(0) ShareShare
ReportReport
Posted on by

Good Morning all 

I currently have a gallery that is serving as a checklist which allows users to complete projects if they are finished. I am currently able to update the SP list I have linked (Has 2 columns, ProjectName, CompleteOrActive). When the user checks the box associated with the project he/she wants to complete it adds the item to a collection called projectsList using this formula:

If(
!IsBlank(Filter(Projects, ProjectName = ThisItem.ProjectName)), Collect(projectsList, ThisItem))

 

and then I have a submit button which bulk updates the SP list using this formula:

ForAll(projectsList, Patch(Projects, LookUp(Projects, ID = projectsList[@ID]), {CompleteOrActive : "Complete"}))

 

It works and filters out the check list gallery, removing the projects that are marked as complete from the gallery. Considering the user makes a mistake and wants to undo the selections they have made - I have added a button "Undo" with the formula:

 

ForAll(projectsList, Patch(Projects, LookUp(Projects, ID = projectsList[@ID]), {CompleteOrActive : "Active"})) - which just re-adds all the projects from the collection to the gallery.

I know there has to be a conditional somewhere that removes items from the collection of checked projects so only the ones that have been selected currently to be re-added - just not sure where that should go or what it should look like 

Any help is appreciated - sorry for the novel of a problem lol

 

Categories:
I have the same question (0)
  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    I figured it out - for those who are having the same problem I had this is how I fixed it:

     

    CheckBox OnCheck: Add checked item to a collection

    If(
    !IsBlank(Filter(Projects, ProjectName = ThisItem.ProjectName)), Collect(projectsList, ThisItem)

     

    CheckBox OnUncheck: Remove Item from the collection

    Remove(projectsList, ThisItem)

     

    Submit button OnSelect: Loops through collection and modifies my SP list marking project as complete - leaves checked item in collection for Undo function
    ForAll(projectsList, Patch(Projects, LookUp(Projects, ID = projectsList[@ID]), {CompleteOrActive : "Complete"}));
    Refresh(Projects)

     

    Undo button OnSelect: Loops through collection and modifies SP list to mark the project as Active, removes the item from the list if given field is "Active"

    ForAll(projectsList, Patch(Projects,LookUp(Projects, ID = projectsList[@ID]), {CompleteOrActive : "Active"}));
    RemoveIf(projectsList, CompleteOrActive = "Active")

     

  • v-siky-msft Profile Picture
    on at

    Deleted

  • michaeldanieal Profile Picture
    on at

    Why do you use RemoveIf() at the end? I don't understand why 'RemoveIf(projectsList, CompleteOrActive = "Active")' is needed?

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 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard