Top
PowerApps

Removing records in SharePoint from PowerApps


PowerApps is getting more and more powerful tool to create business apps in the “no-code” approach. Using SharePoint as the data source is somehow natural (although there are alternatives, like an SQL Server or Common Data Service) thanks to their tight integration.

It is very easy to create a new form for SharePoint list using PowerApps functionalities. Forms present in the tool with a single click can be bond with any list and by providing record ID switch them between edit and new mode, as well as view.

Adding SharePoint forms in PowerApps
Building SharePoint forms in PowerApps

When building a business application however it is often very important to also have the option to remove records, not only to add or edit them. There is yet no ootb option in PowerApps present to support this scenario, however with a little help from Microsoft Flow everyone can achieve it.

How to remove records in SharePoint from PowerApps?

Using Microsoft Flow obviously! First think about the logic of your app, regarding how user can access that specific item. For example, use a “Gallery” control or a “Data table”. Once user selects a record transit him to another screen with a form, where the selected record ID is used as the input for the form.

Below a form add buttons, to save and delete the record. Handling save is easy, this comes with the form almost ootb. Simply use the following expression in the “OnSelect”:

SubmitForm(NAME_OF_YOUR_FORM)

To handle deleting, use “Action” –> “Flows” and from there create a new Flow. For my purpose I have create a generic flow, able to handle removal from any list within a specific site:

Generic Flow for removing records from SharePoint
  1. This is a trigger actions – a request from PowerApps.
  2. I’m setting initial value of the Status Code, that will be then returned to PowerApps.
  3. Compose action, to collect ID of the record that is going to be deleted.
  4. Compose action, to collect name of the list, from which the record is going to be deleted.
  5. The actual “Delete” action. It takes ID and Entity name as the “Custom value” parameters:

6. Setting variable is only done, if the action 5 ends up with any sort of failure. This action has the “Run after” configured, to start only if the deleting fails.
7. After deleting is done, a status code (either 200 or 409) is returned back to PowerApps (this is quite new functionality, since April 2018, https://flow.microsoft.com/en-us/blog/return-data-to-powerapps/).

Handling response from Microsoft Flow in PowerApps
Handling response from Microsoft Flow in PowerApps
  1. Name of the variable, that stores response from Flow.
  2. Flow name and parameters run on button’s “OnSelect” action.

Next steps

After  response is collected you can handle it. Eg. create a hidden panel with a message, that is only shown if the response is different than 200 and the other one, when it is equal:

Set(
    ResponseCode,
    DeleteRecordinSharePoint.Run(
        SharePointIntegration.Selected.ID,
        "My entity"
    )
);
If(
    Value(ResponseCode.status) <> 200,
    SHOW_ERROR_HIDDEN_PANEL,
    SHOW_SUCCESS_HIDDEN_PANEL
)

Like what you’re reading? Leave a comment!


Tomasz Poszytek

Hi, I am Tomasz. I am expert in the field of process automation and business solutions' building using Power Platform. I am Microsoft MVP and Nintex vTE.

No Comments

Post a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.