cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Creating undo function using Patch()

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

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")

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

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")

 

Deleted

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,711)