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

Get Multiple ID's from one data source and patch into another data source

Hello,

I'm building an app where I'm storing user inputs into a collection called UserCollection. Then, onButtonClick, Patching it to a sql server data source called (dbo.ItemsTable). It has auto increment number column (ItemId) while inserting rows into it. On Another Button click, I need to grab the rows from the dbo.ItemsTable and insert the rows in another sql table called dbo.AllItems. How do I insert multiple rows from one table to another? I can only do one row at a time. Is there a formula in PowerApps? Thanks in Advance. Hope I explained properly.

4 REPLIES 4
russrimm
Microsoft
Microsoft

Check out the ForAll function, it sounds like what you're looking for.  You can do a ForAll along with a Patch or Collect to accomplish this.

I tried the ForAll function but didn't had luck. It only writes one row into the second table and errors out with "Item created already on server". How do I insert multiple rows? Appreciate your input on this.

russrimm
Microsoft
Microsoft

For the first one have you tried something like

ForAll(UserCollection.AllItems,Patch('ItemsTable',{ItemId:value(itemid.text),user:username.text}))  (assuming the sql column is ItemId and the value in the app is Itemid.text, just as an example)

 

For the second one you could have it collect or clearcollect(items,'ItemsTable') and then ForAll(items.Allitems,Patch('AllItems',{col1:blah.text,col2:blah.text}))

I'm able to insert the items collected in "UserCollection" and Patch the items into table1 of sql server (Which generates id 215, id 216 in ItemID Column). How can I retrieve only the id of the two values from table 1(ItemId column name) and Patch the items in table2?  ForAll is bringing the whole table1 id values. I Hope it was clear. Thanks for your help. 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,325)