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 / Retrieve an ID from SQ...
Power Apps
Answered

Retrieve an ID from SQL table after patching a record to it

(0) ShareShare
ReportReport
Posted on by 27

Hi

I'm fairly new to PowerApps. I have two forms in my app, one called Supplier and another called Supplier Services. 

On the Supplier form I have a submit button:

 

Patch('[dbo].[tblCompany]',Defaults('[dbo].[tblCompany]'),{Name: TextInput1.Text});Navigate(SupplierServices,ScreenTransition.Fade)

 

Now on the Supplier Services screen, I need to get the value of the ID back from SQL for the newly patched Company so that I can assign services against that company. 

 

 

On the submit button of the Supplier Services form I want to patch the services across, along with the SupplierID

Patch('[dbo].[tblSupplierServices]',Defaults('[dbo].[tblSupplierServices]'),{SupplierID:Value(TextInput3.Text),ServiceType: ComboBox2.Selected.ServiceID});Navigate(SubmissionScreen,ScreenTransition.Fade)

 

At the moment I can't seem to recall the ID, I have played around with variable but have had no joy.

 

Is there a way? 

 

Many thanks

Gareth

Categories:
I have the same question (0)
  • TML Profile Picture
    185 on at

    By ID, do yoou mean a GUID or Auto Increment created in SQL?  If so, I think you will have to query your company table with filter or lookup and using enough field/data to uniquely identify the company if company name is not enough.  You can pass the info between screens with the Navigate function optional parameters and retrieve the record OnVisible of the second form.  If I understand your question correctly. 

  • Verified answer
    timl Profile Picture
    37,212 Super User 2026 Season 1 on at

    Hi Gareth,

     

    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.

    The same method applies if you were adding multiple records via Collect, as I mentioned here:

    https://powerusers.microsoft.com/t5/General-Discussion/Can-you-return-primary-key-ID-after-DB-insert-SQL-Server/m-p/90812/highlight/true#M34246

    Hopefully, this gives you enough to work with. If not, let us know.

  • ggeorge Profile Picture
    27 on at

    Hi Timl

     

    This is great, thank you.

     

    I noticed in the collections tab it has the ID. How do I recall this into a text box on the Supplier Services form. I keep getting an error message.

     

    Thanks again.

     

    Gareth

  • ggeorge Profile Picture
    27 on at

    Solved

     

    First(NewCompany).CompanyID

     

    Thanks for you're help, that has been bugging me for hours 🙂

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 481

#2
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#3
11manish Profile Picture

11manish 291

Last 30 days Overall leaderboard