Skip to main content

Notifications

Community site session details

Community site session details

Session Id : M0jOIbpMKjUdav3LtEHsba
Power Apps - Building Power Apps
Answered

Patch function is updating randomly items and not the one I selected

Like (0) ShareShare
ReportReport
Posted on 9 Oct 2023 19:28:29 by 9

Context: I need to update the status of sharepoint lists using power apps. There are 5 lists that have the same structure and need to be updated. I created a collection with them all and then used the patch function.  The problem is that the item i select doesn't update, instead a random item is updated.

 

 

 

// Update UnifiedCollection
Patch(
UnifiedCollection,
LookUp(UnifiedCollection, ID = AllTable.Selected.ID && Title = AllTable.Selected.Title),
{
RequestStatus: {Value: "Approved by AO"}
}
);

// Update corresponding SharePoint list
Switch(
AllTable.Selected.SourceList,
"EventRequests", Patch(EventRequests, LookUp(EventRequests, ID = AllTable.Selected.ID && Title = AllTable.Selected.Title), {RequestStatus: {Value: "Approved by AO"}}))

 

I have 4 more SourceList that will use the same, thats why i wont put them all here.

  • Verified answer
    dallabroda Profile Picture
    9 on 20 Oct 2023 at 19:35:23
    Re: Patch function is updating randomly items and not the one I selected

    After reading this response, I've decided to ignore it because I thought simply changing the order wouldn't make a difference. One week later with a different approach already implemented I come here to check for answers and for some reason I decide to do as you suggest...and it works. 

     

    Thanks for the help.

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on 09 Oct 2023 at 21:05:07
    Re: Patch function is updating randomly items and not the one I selected

    @dallabroda - to me at least, there is nothing obviously wrong with your expression. 

     

    As I understand it, you have two SharePoint lists which have exactly the same schema and you have collected both into a single "Unified Collection".

     

    Looking at your expression, I am guessing you have differentiated which data source is which by adding a "helper" column into the Collection to identify which row belongs to which table ("EventRequests", "Something Else" etc). Given the schema of both tables are the same, you have needed to use both the ID field and the Title field to identify the correct record.

     

    I have seen this before in the past and there was no obvious reason why the Patch statement failed. If you add a notification message for example between each Match Result in your Switch statement you will be able to confirm that the Switch statement is definitely not firing e.g.

     

    Notify("EventRequests",NotificationType.Information);

     

    One potential solution is to move the section where you patch the Collection to the end (so in other words have it run after you run the Patch statements to your data source). Because to me at least, I cannot see any obvious dependency or reason for running that operation first.

  • Michael E. Gernaey Profile Picture
    41,020 Super User 2025 Season 1 on 09 Oct 2023 at 20:08:33
    Re: Patch function is updating randomly items and not the one I selected

    hi @dallabroda 

     

    You do not specify which list is wrong, I am assuming its in the Switch but I dont like guessing.

     

    Also, the patch code, per se, looks fine, which means its an issue with the Selected Record and or the Data in the back end.

     

    Please put two labels on the screen. 

    For LabelText1.Text put AllTable.Selected.ID

    For Label 2.Text put the AllTable.Selected.Title

     

    Now you are saying it does a "random" row, but I don't think that's true. I believe its fully got a pattern, based on whatever is the issue in the Data or the Code (the patch looks fine, so its the other code), not that its actually random.

     

    But you need to provide more details.

    1. Prove that AllTable.Selected.ID has a value of XYZXLDSF whatever, and Selected.Title has value of "asfasdf" and it just did a completely random row (either in the right table or wrong).

     

    I think if you can repro this easily, then it will be something simple. But first you need to create a repro and showing those values here as well as the values in the List/Table so we can help better.


    If you like my answer, I would really appreciate if you please Mark it as Resolved, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

  • WarrenBelz Profile Picture
    146,645 Most Valuable Professional on 09 Oct 2023 at 20:08:29
    Re: Patch function is updating randomly items and not the one I selected

    Hi @dallabroda ,

    I suspect it is because the ID of the relevant item is different in each list. If Title is the common field you are looking for, just use that in the SharePoint patch.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard
Loading started