cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PierreGiusti
Level: Powered On

Get ID from SQL to Powerapps - II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Get ID from SQL to Powerapps - II

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

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: Get ID from SQL to Powerapps - II

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

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

PierreGiusti
Level: Powered On

Re: Get ID from SQL to Powerapps - II

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

Highlighted
Dawidvh
Level 10

Re: Get ID from SQL to Powerapps - II

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)

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,921)