cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Collector
Kudo Collector

Update multiple records

I have an app, that allows filtering Employees by a Manager. Once you select several items with a Checkbox1, you can update their Manager field through Office365Users.Manager data connection.

 

The button has this code and it does work; however, as expected it only works for the first selected item:

Patch('Employee Directory',First(Filter(BrowseGallery.AllItems, Checkbox1.Value=true)),{Supervisor:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", Claims:Concatenate("i:0#.f|membership|",Office365Users.Manager(First(Filter(BrowseGallery.AllItems, Checkbox1.Value=true)).Email.Email).Mail), Department:"", DisplayName:Office365Users.Manager(First(Filter(BrowseGallery.AllItems, Checkbox1.Value=true)).Email.Email).DisplayName, Email:Office365Users.Manager(First(Filter(BrowseGallery.AllItems, Checkbox1.Value=true)).Email.Email).Mail, JobTitle:"", Picture:""}})

 

I'm trying to make it work for several records at once but cannot seem to pair Patch and ForAll properly.

Modify or create a set of records in a data source

Patch( DataSource, BaseRecordsTable, ChageRecordTable1, [, ChangeRecordTable2, … ] )

 

I'm almost positive I need to create a new collection of those employees that were selected with Checkbox1. The collection looks good:

ClearCollect(SelectedUsers,Filter(BrowseGallery.AllItems, Checkbox1.Value=true))

 

Your help is much appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Memorable Member
Memorable Member

Re: Update multiple records

@bloodoff

I don't know if I understood correctly. But it looks like very easy task and you were on the right track.. There is no need to use forall or other functions. Once again.. Create a new app.. Add one button what will crate a test collection. Change OnSelect property of that button to 

ClearCollect(TestTable,{id: 1, Column1: "test1"}, {id: 2, Column1: "test2"},{id: 3, Column1: "test3"}, {id: 4, Column1: "test4"}, {id: 5, Column1: "test5"})

 

Now add a blank gallery and change the items property to TestTable. Insert a label into that gallery to display Column1 and CheckBox

 

Now create another button what will pull selected rows from that gallery and collecting them to EditCollection by changing OnSelect property to 

Collect(EditTable,Filter(Gallery1.AllItems, Checkbox1.Value=true))

 

Now Insert an InputText and third submit button what will update main TestCollection by changing OnSelect property to 

UpdateIf(TestTable,id in EditTable.id, {Column1: TextInput2.Text})

 

Now click on that first button and test it. If this is what you  wanted then it is very easy to change it in your app

View solution in original post

9 REPLIES 9
Highlighted
Kudo Collector
Kudo Collector

Re: Update multiple records

Highlighted
Super User
Super User

Re: Update multiple records

That is a lot for me to recreate to test but what if you just remove the First? Wouldn't that patch all of the records? 

 

I have a complicated solution for this problem with ForAll and a separate collection but I don't think you need it. 

 

 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
Highlighted
Kudo Collector
Kudo Collector

Re: Update multiple records

Invalid argument type (Table). Expecting a record value instead.

 

This feels very similar to what user Urvi said here:

https://powerusers.microsoft.com/t5/General-Discussion/Useful-features-of-powerapps-15-Multiple-Batc...

"Patch function is not taking second argument as "table".

Highlighted
Kudo Collector
Kudo Collector

Re: Update multiple records

This code down below does update all selected records which is nice but it's updating them to the same value as First is used. Now I gotta figure out how to grab each value from SelectedUsers collection. Any ideas?

 

ClearCollect(SelectedUsers,Filter(BrowseGallery.AllItems, Checkbox1.Value=true));Patch('Employee Directory',SelectedUsers,ForAll(SelectedUsers,{Supervisor:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", Claims:Concatenate("i:0#.f|membership|",Office365Users.Manager(First(SelectedUsers).Email.Email).Mail), Department:"", DisplayName:Office365Users.Manager(First(SelectedUsers).Email.Email).DisplayName, Email:Office365Users.Manager(First(SelectedUsers).Email.Email).Mail, JobTitle:"", Picture:""}}))

Highlighted
Kudo Collector
Kudo Collector

Re: Update multiple records

@Shanescows I can possibly imagine a solution where First is still used and at the same time the collection is reduced by 1 until nothing (if it's even doable). Any other simple way I'm missing?

Highlighted
Memorable Member
Memorable Member

Re: Update multiple records

@bloodoff

I don't know if I understood correctly. But it looks like very easy task and you were on the right track.. There is no need to use forall or other functions. Once again.. Create a new app.. Add one button what will crate a test collection. Change OnSelect property of that button to 

ClearCollect(TestTable,{id: 1, Column1: "test1"}, {id: 2, Column1: "test2"},{id: 3, Column1: "test3"}, {id: 4, Column1: "test4"}, {id: 5, Column1: "test5"})

 

Now add a blank gallery and change the items property to TestTable. Insert a label into that gallery to display Column1 and CheckBox

 

Now create another button what will pull selected rows from that gallery and collecting them to EditCollection by changing OnSelect property to 

Collect(EditTable,Filter(Gallery1.AllItems, Checkbox1.Value=true))

 

Now Insert an InputText and third submit button what will update main TestCollection by changing OnSelect property to 

UpdateIf(TestTable,id in EditTable.id, {Column1: TextInput2.Text})

 

Now click on that first button and test it. If this is what you  wanted then it is very easy to change it in your app

View solution in original post

Highlighted
Kudo Collector
Kudo Collector

Re: Update multiple records

@Sienna I think that helped 🙂 This is the final code:

 

ClearCollect(SelectedUsers,Filter(BrowseGallery.AllItems, Checkbox1.Value=true));UpdateIf('Employee Directory',ID in SelectedUsers.ID,{Supervisor:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", Claims:Concatenate("i:0#.f|membership|",Office365Users.Manager(Email.Email).Mail), Department:"", DisplayName:Office365Users.Manager(Email.Email).DisplayName, Email:Office365Users.Manager(Email.Email).Mail, JobTitle:"", Picture:""}})

 

@Sienna Do you think this wouldn't work: "I can possibly imagine a solution where First is still used and at the same time the collection is reduced by 1 until nothing (if it's even doable)"

Highlighted
Memorable Member
Memorable Member

Re: Update multiple records

@bloodoff

It is very hard to tell what exactly you are trying to do with that code. What exactly you want that app to do, what setting you got and so on.. I'm always saying if anyone get into a trouble with their app then create a new simple app and sort the issue on simple example just as I wrote you above. Proceed step by step until the problem is solved. Then move to the original app and fix it from that simple app. Try to make new test app by following each step I gave you above. Then imagine that the TestTable is you main database. Try to play with it until you get the result you want and then implement it in your original app

Highlighted
Anonymous
Not applicable

Re: Update multiple records

We cant depend on Patch or Update if. Some time they even fail for records less than 500. Also they are slow.

Try creating a stored procedure for it and then calling it in a flow.

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,198)