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 / How to get created rec...
Power Apps
Answered

How to get created record id from patch function ?

(1) ShareShare
ReportReport
Posted on by 149

I want to get record Id which is created by Patch function from PowerApps.

Is there any way to get that record Id so that I can use that Id to set in another record's lookup field

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

    Hi @rajmilansinh 

    The return value from Patch will include any server generated values. The code in the following post might be of interest to you...

     

    https://powerusers.microsoft.com/t5/General-Discussion/Retrieve-an-ID-from-SQL-table-after-patching-a-record-to-it/td-p/142441

     


     

    The return value from Patch includes any server generated identity values. If you did this for example,

    ClearCollect(NewCompany,
     Patch('[dbo].[tblCompany]',Defaults('[dbo].[tblCompany]'),{Name: TextInput1.Text})
    )

    ... you could use NewCompany.ID to retrieve the identity value that SQL Server generates.

     


  • kevinroy Profile Picture
    14 on at

    Several web sites recommend using ClearCollect to load the returned record.   I've had difficulty with this; I believe it's because ClearCollect creates a table, and accessing the ID for the newly-created record is not as straightforward as the following method.

     

    Instead, I have used UpdateContext with success.  For example:

     

    UpdateContext ({newRecord: Patch ('Table Name', Defaults('Table Name'), {Json key value pairs values to store in the item item})})

     

    Then, for example, "newRecord.ID" returns the ID for the new item and "newRecord.Title" returns the title.

    Of course, you can use Set instead, if you need the new record to be accessible across several screens.

  • JonSov Profile Picture
    4 on at

    How do you do this inside of a ForAll loop? You cant do clearcollect, and collect doesnt work for me because I need the value to reset every iteration of the loop.

  • kevinjroy Profile Picture
    2 on at

    First, clear a collection to contain the patched items:

    ClearCollect (patchedItems, {}); Clear (patchedItems)

     

    ForAll (collection of items to patch, 

      Collect (

          patchedItems,

          {aPatchedItem: Patch (....)}

       )

    )

    This gives you a full collection of patched items.   I'm not clear on why you need to reset a value for every iteration, but you perhaps can achieve your goal by inspecting the collection "patchedItems"

  • Baudelaire Profile Picture
    110 on at

    This is how I do it as well, for SharePoint that is.  If I know I only want the ID of the item (to pass to a flow for example, but the OP's use case is also valid), I do this:

    UpdateContext ({newRecord: Patch ('Table Name', Defaults('Table Name'), {Json key value pairs values to store in the item item}).ID})

     

    Now newRecord is just the item ID.

     

     

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
wolenberg_ Profile Picture

wolenberg_ 119 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 107 Most Valuable Professional

#3
Haque Profile Picture

Haque 103

Last 30 days Overall leaderboard