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 / Get ID from SQL to Pow...
Power Apps
Answered

Get ID from SQL to Powerapps - II

(0) ShareShare
ReportReport
Posted on by 51

Hi, PowerApps have a function to get ID from a register added in SQL?

 

Situation:

 

In a EditScreen, I click on SubmitForm(EditForm_X) to add data, at this moment SQL database generate a ID to this register.

 

After the ID was generate, I need to stay in EditScreen and know what was the ID who database assigned, to use it in another Patch command.

 

How can I do that?

 

Thanks.

 

Pierre

Categories:
  • Verified answer
    v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @PierreGiusti,

     

    If you mean the Primary ID auto-generated by SQL Server table, once the form control submit the record successfully, we could take use of the form.LastSubmit property to get the ID generated.

    For example, if the ID is named ID in SQL Server table, then the proper way to get its value is:

    Editform1.LastSubmit.ID

    "

    LastSubmit – The last successfully submitted record, including any server generated fields.

    "

    Reference: Editform control in PowerApps

     

    Regards,

    Michael

  • PierreGiusti Profile Picture
    51 on at

    Hi, I inserted UpdateContext({VarLastID: EditFormCalendInsert.LastSubmit.IDCalendario}) function in propriety “OnSuccess” at EditForm1 and PA returns the ID correctly.


    My doubt is if exist the possibility of return de wrong ID if some situation occurs, like simultaneous insertion, trouble with communication, etc…


    Thanks.


    Pierre

  • Dawidvh Profile Picture
    1,346 on at

    Hi Pierre.

     

    Keep in mind that if you use patch combined with the default function, patch will return certain attributes form the newly created record \ row, which you can then use to get the id.

     

    Set(varnametostoreID, Patch(datasource,Defaults(datasource),
    {fieldname:"FieldValue"}).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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard