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.
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.
@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.
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
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
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional