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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

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

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,401)