Update multiple SharePoint items in different lists with Power Automate from Power Apps

Today we’re going to update SharePoint items in multiple lists using Power Automate BUT from a Power Apps app! Sounds exciting already 😁

If you prefer to watch a video instead, I’ve recorded one on my YouTube channel too.

Scenario

Let’s imagine with have an app we use to edit our SharePoint data. But the specific data we want to edit might be in multiple lists. Therefore we want consistency between the lists.

When we amend our Main List in Power Apps, we want this change to spread across any other lists where that specific data is. Dynamically! No hard-coded values for the lists 😉

SharePoint items

We have a SharePoint site with 3 lists:

  • Main List
  • List A
  • List B

The idea for this scenario is to have a item Title only once in each list. Meaning the same Title cannot be twice in the same list.

But the item Title can appear in the Main List, and perhaps in List A and/or List B. Below are my current SharePoint items:

As you can see in the screenshots above, the title “SharePoint for Admins” appears in all 3 lists, while “Copilot Studio Autonomous Agents” only appears in the Main List and List A.

Some items also only appear in the Main List (i.e.: Copilot Studio: Beginner Tutorial). You get the idea…

Also note that for each list, the metadata (columns) are different except the Title column which is present on all three (3). It will be important for later.

Power Apps

I have a little app which contains a gallery connected to the Main List. This is the only data source connected to my app.

When I click on the Edit button (pencil), I have created a popup where I see the CurrentTitle (text/label) and can change the NewTitle (text input). Those 2 elements will be important because they’ll be the input parameters for our Power Automate flow later on 😉

Let’s go over a couple of formulas in the app to understand some important things.

When we click on the Edit button (pencil), we set 2 variables: varTitle and varItemID.

  • varTitle will grab the current title to be able to display it in the popup (and find other items later!)
  • varItemID will be used in the PATCH function to update the specific item from the popup

When the popup is open, we have a Cancel button with the below formula in the OnSelect property:

UpdateContext({showPopup:false}); Reset(txtInput_newTitle);

The Confirm button (green checkmark) contains the following formula in the OnSelect property:

Patch(
    'Main List', {ID: varItemID},
    {
        Title: txtInput_newTitle.Value
    }
);

UpdateContext({showPopup:false}); Reset(txtInput_newTitle);
Refresh('Main List');

We will come back later in this formula to add our flow 🙂

Power Automate

Time to build our flow! We can start creating the flow directly from Power Apps by clicking on the 3 dots from the left navigation and click Power Automate > Create new flow > Create from blank.

What I usually do is create the flow in Power Apps so it’s attached, then go the Power Automate portal to continue. The reason is we always need to test the flow multiple times at different steps.

So… for the Power Apps V2 trigger, we’re going to add 2x text inputs:

  • CurrentTitle
  • NewTitle

Remember, I mentioned them earlier 😉

Then we need get all the lists dynamically. We’ll use the Send an HTTP request to SharePoint action BUT we’ll also add a filter for the Uri.

So, we know the app will update the Main List, therefore we don’t need to include it in the output. In my case, the lists are generic/custom lists, which means the BaseTemplate is 100. And we also going to skip all the Hidden lists (because mine are not hidden – be careful if yours are for your scenario!)

Note the Uri as follows:

_api/web/lists/?$filter=Hidden eq false and BaseTemplate eq 100 and Title ne 'Main List'

Then, we’ll need to go through each list to get the items. Once again, we’re going to add a filter to get only what we need.

Add an Apply to each action with the value of the previous step (HTTP – Get Lists). Sometimes the value does not appear in the dynamic content; Fear not! Just add the expression yourself. In my case it will be:

body('HTTP_-_Get_Lists')?['value']

Insert a Get items action as follows:

Note that getting the List Name will be dynamic using the id (choose “custom” in the dropdown):

items('ATE_Lists')?['id']

Then for the Filter Query, we only want the items which have the CurrentTitle. Don’t forget the single quotes!

If we run the flow at this stage, we’re going to have a lot of things we’re not really interested in… So let’s trim things a bit more 😁

After the Get items, let’s add a Select action to create an new array with only what we need.

The itemID formula is: (“ID” is uppercase!)

item()?['ID']

The itemTitle formula is:

item()?['Title']

Update the item(s)

Finally, let’s update the items. But we’re going to use the Send an HTTP request to SharePoint action within another Apply to each instead of the built-in Update item because we only want to update the Title and the other metadata is different on each list.

This time we’ll use a POST method with Headers as mentioned in the official documentation.

Note the Uri is as follows:

_api/web/lists/GetById('@{items('ATE_Lists')?['id']}')/items(@{items('ATE_items')?['itemID']})

Configure the flow in Power Apps

Let’s go back to Power Apps and insert our flow in the OnSelect property of our Confirm button.

Our first parameter is the current title which is varTitle, and then our new title will be the user’s text input.

Test the flow!

From the app, we’re going to amend the “SharePoint for Admins” title. This title is in the Main List (which will be updated by the app with the PATCH function), and also in List A + List B.

When the flow runs successfully, the items in all 3 lists will be amended 🥳

Will the flow fail if the item is only in the Main List?

The answer is no! The flow will not fail if the item you wish to amend is only in the Main List and nowhere else.

The “Copilot Studio: Beginner Tutorial” title is only in the Main List, so let’s change it.

The flow runs successfully, updates are made in the Main List via the app, but then there’s simply nothing to change in the other lists 😉

Thanks for reading! 🙂

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading