Power Apps | How to Create a Temporary Delete Function Within a Gallery

The gallery in PowerApps is a customizable tool used to share important information from a SharePoint list. This can include emails and names of new leads, or information about your largest and most loyal clients. Accidentally losing that information could be extremely inconvenient. Oftentimes, we hit the delete button by accident and wish there was an undo button. Mistakes happen so fast! PowerApps can actually help reduce the amount of potential deletion. We can add a validation modal with the “Are you sure you want to delete this item?”. In some cases, this will work and prevent the mistake. In most cases, however, this slows down the user experience, or users click without reading, and there is still a chance something gets deleted before hitting save. This post looks at adding a temporary delete function within a gallery. This will allow the end-user to hit “undo” until they hit the save button to apply their changes.

Before delete

This image displays a gallery of expenses before hitting the delete button.

After delete

Notice the element in the first line. It is now crossed, and the action buttons on the right changed to “Undo”.

This image displays a gallery of expenses after hitting the delete button. It shows the undo button in its place.

Here are the steps to create this temporary delete function:

Step 1 to create a temporary delete function within a gallery:

On the “Delete” button set the OnSelect to :

If(IsBlank(LookUp(TempDelete,ThisItem.ID=tID,tID)),
Collect(TempDelete,{tID:ThisItem.ID}),
RemoveIf(TempDelete,ThisItem.ID=tID))

What this formula does:

If the item you delete does not exist in a collection called “TempDelete” then collect the ID of the item deleted to this TempDelete Collection. If the item does exist then remove it from the “TempDelete” Collection as you are “Undoing” the Delete.

*Note: I am using a SharePoint List in this example so ID will always be unique. If you do not have an ID column you will need to use a unique column in your dataset.

New call-to-action

 

Step 2:

Next, use this formula: ThisItem.ID in TempDelete.tID to indicate that the row has been “Temporarily Deleted”. In this case, when the row is deleted, all the labels with Strikethrough will be set to true.

On the label under Strikethrough paste the code: ThisItem.ID in TempDelete.tID which will return a true or false so you don’t need to include an IF statement.

We have the icon changing from a “Trash” icon to an “Erase” icon. The “Trash” icon when the item is not deleted and the “Erase” icon when the item is deleted. On the icon add the following formula: If(ThisItem.ID in TempDelete.tID,Icon.Erase,Icon.Trash)

You can also add a rectangle Icon to the row and make it a faded grey or red or any other indication you want to add. Use this code: “ThisItem.ID in TempDelete.tID” to determine if it’s deleted or not.

Step 3:

Lastly, we need to make these deletes apply when the save button is hit. When this occurs the contents will be deleted from the SharePoint list. You can also have a Yes/No column called “Deleted” which you can mark true if they delete for a consistent undo feature.

This is the formula used to delete from the SharePoint List when the save button is hit: If(CountRows(TempDelete)>0,ForAll(TempDelete, RemoveIf(ExpenseItems_1,ID=tID)))

We then run any other formulas concurrently or steps after as required.

In today’s evolving workforce, we have all experienced the stress of accidentally deleting something important. Implementing this simple three-step process will help streamline the user experience and reduce the stresses of the workplace. After all, does anyone really read the “Are you sure you want to delete this item?” before hitting “Yes.”? If you want to learn more about increasing productivity in your organization, start by booking a consultation below:

New call-to-action

Subscribe our newsletter

Enter your email to get latest updates.