cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

ForAll - Patching records - Item created already in the server

Hello Community, I need help in a formula that inserts records into a data source. When I use a ForAll statement, I can only insert one record.  Couldn't Patch multiple records as PA is throwing an error message "Item already created on server". Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: ForAll - Patching records - Item created already in the server

Hi @Kitz ,

Ok, I think I understand.

collection1 has these fields: ItemID, ItemNumber

collection2 has these fields:  ItemID, TransID

Do you want to add TransID value in collection1?

If so, try this formula:

ClearCollect(collection3,AddColumns(collection1,"TransID",""));  //add one column with empty value
ForAll(collection2,Patch(collection3,LookUp(collection3, ItemID=collection3[@ ItemID]),{TransID:TransID})); //update this empty field
ClearCollect(collection1,collection3) //update collection1 with the data of collection3

Then, TransID value will be added into collection1.

Please replace collection1,collection2,collection3 with your collection name.

 

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Advocate I
Advocate I

Re: ForAll - Patching records - Item created already in the server

Hi @Kitz 

Can you provide a bit more information about the source/code where you are having this trouble?

Thank you.

Highlighted
Helper I
Helper I

Re: ForAll - Patching records - Item created already in the server

Hi @FernandoTC ,

Hope this helps you..

 

ForAll(ShoppingCart,Collect(Collection1, Patch(
'[dbo].[UserInfo]',
Defaults('[dbo].[UserInfo]'),
{
Comment: "",

Location: LocationDD.Selected.Text

})))

This code generates rows in "Collection1" depending on items in ShoppingCart (This is a Collection containing Product Info). The UserInfo table contains user information only. I'm trying to patch items of ShoppingCart (like ItemDesc, ItemNumber) based on ID generated in UserInfo table. 

 

ForAll(Collection1,Patch(
'[dbo].[ProductLines]',Defaults('[dbo].[ProductLines]'),
{
ProdID:Value(ID) ,
ItemId: Shoppingcart.ItemId,
}))

 

PowerApps errors out with data already created on server. Please help! TIA

Highlighted
Community Support
Community Support

Re: ForAll - Patching records - Item created already in the server

Hi @Kitz ,

If you want to update multiple records at the sam time, the right syntax should be:

ForAll(collectionname,Patch(tablename,Defaults(tablename),{fieldname1:fieldname11,fieldname2:fieldname22})

Fieldname1 and fieldname2 is the fields in table.

Fieldname11 and fieldname22 is the fields in collection.

So try to modify your formula:

ForAll(Collection1,Patch(
'[dbo].[ProductLines]',Defaults('[dbo].[ProductLines]'),
{
ProdID:Value(ID) ,
ItemId: ItemId,   //ProdID and ItemId should be in '[dbo].[ProductLines]', ID and ItemId should be in Collection1
}))

Here's a doc about this for your reference:

https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper I
Helper I

Re: ForAll - Patching records - Item created already in the server

Hi @v-yutliu-msft ,

Please see the attachments,

I was successful in patching one/multiplerecords in the datasource1 and collect those patched records to a collection called "SecondCollection" (See SecondCollection.png). Now, How do I take the 'TransID' from "SecondCollection" and add that to the "FirstCollection" (FirstCollection.png). After adding it to the FirstCollection, I need to patch the columns ItemID, ItemNumber,TransID (These are columns in my datasource).

 

Hope I'm able to explain you clearly.

Highlighted
Community Support
Community Support

Re: ForAll - Patching records - Item created already in the server

Hi @Kitz ,

Ok, I think I understand.

collection1 has these fields: ItemID, ItemNumber

collection2 has these fields:  ItemID, TransID

Do you want to add TransID value in collection1?

If so, try this formula:

ClearCollect(collection3,AddColumns(collection1,"TransID",""));  //add one column with empty value
ForAll(collection2,Patch(collection3,LookUp(collection3, ItemID=collection3[@ ItemID]),{TransID:TransID})); //update this empty field
ClearCollect(collection1,collection3) //update collection1 with the data of collection3

Then, TransID value will be added into collection1.

Please replace collection1,collection2,collection3 with your collection name.

 

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,386)