Powerapps remove item from sharepoint list

I came to know the business requirement to have a screen to let users click a delete icon for a person’s entry in a gallery, which will then remove that person from the selected list in SharePoint.

Solution

We will be using PowerApps to fulfill this requirement. The screen has Gallery within the gallery to display the users. We call it MainGallery and PersonGallery. The  main gallery to display the items, and PersonGallery to display the person’s list

Main Gallery

  • Insert the Gallery [Name: MainGallery] and set Items property to

SPListName

Person Gallery[Sub Gallery]

  • Select the main Gallery and insert another gallery [Sub Gallery – Name: PersonGallery]
  • Set the Items property of PersonGallery to [MultiplePeople – ColumnName]

ThisItem.MultiplePeople

  • Insert label and Set Text property to

ThisItem.DisplayName

  • Insert Icon and set an icon to something [X or Trash]

Sample UI

Setup

Action/Steps

Set the OnSelect property of Trash Icon to

We have 4 steps and split into multiple for readability

  1. Get the Email for the person to delete

Set[ personToRemove, ThisItem.Email

];

Delete an item or all related items using Remove and RemoveIf functions from PowerApps

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

After Delete

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

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.

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:

Video liên quan

Chủ Đề