web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can you return primary...
Power Apps
Answered

Can you return primary key ID after DB insert SQL Server

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I want to insert a row using the following formula:

 

ClearCollect(TempName, { Name: "John"}, { Name: "Doe" }); Collect('[dbo].[Name]', TempName)

This will insert two rows into my SQL Server table Name.

(1, John) , (2, Doe)

I basically want to return the two ID's 1 and 2 into my application. Is this possible with PowerApps at present?

Categories:
I have the same question (0)
  • Verified answer
    timl Profile Picture
    36,774 Super User 2026 Season 1 on at

    Hi @Anonymous

     

    Yes, it's possible to retrieve the ID values of the records that you insert.

    Once the Collect function inserts the rows into the SQL table, it returns the contents of the table and this includes any auto-generated values from the data source.

     

    For example, this formula would collect the results into a collection called ResultsTable.

     

    ClearCollect(TempName, { Name: "John"}, { Name: "Doe" }); 
    ClearCollect(ResultsTable, Collect('[dbo].[Name]', TempName))

    Note that ResultsTable will include all other records from [dbo].[Name]. If you want to more precisely retrieve the ID value for the records that you insert, an alternative method is to insert single records by calling the Patch function. The Patch function returns the inserted record, which also includes the ID value. 

     

     

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    If you use a Collect call, then you cannot get the ids. You can use a Patch call, however, where it returns the item that was inserted (or modified), including the (identity) id field.

     

    In your case you can have an expression like the one below:

    ForAll(
     TempName,
     Collect(
     temp2,
     Patch(
     '[dbo].[Name]',
     Defaults('[dbo].[Name]'),
     { Name: Name })))

    For each item in the TempName column, it will execute a Patch with the defaults for the table (which causes an insert operation), and collect the result into the temp2 collection. That collection will have the ids for the newly inserted items.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 493 Most Valuable Professional

#2
11manish Profile Picture

11manish 479

#3
Haque Profile Picture

Haque 328

Last 30 days Overall leaderboard