#PowerPlatformTip 79: 'Retrieve Record Details Post-Update'
TL;DR: Capture a just-created or updated record’s details (like its ID) by wrapping Patch in
Set()or readingForm.LastSubmitright after submitting.
💡 Challenge
When working with Power Apps, you often need to retrieve details of a record that has just been created or updated. This information might include the ID of the new/updated record, which is essential for further processes or user notifications.
✅ Solution
You can obtain the details of the newly created or updated record by wrapping a variable around the Patch function or using the Form.LastSubmit property to immediately access record details post-update.
🔧 How It’s Done
Here’s how to do it:
-
Using a Variable with Patch Function:
🔸 Syntax:Set(RecordDetails, Patch(DataSource, BaseRecord, ChangeRecord))🔸 Example:
Set(NewRecord, Patch(Products, Defaults(Products), {Title:"New Product"}))🔸 Retrieval: Use
NewRecord.IDto retrieve the ID of the newly created record. -
Using Form.LastSubmit Property:
🔸 Setup: Ensure the form is properly linked to your data source.🔸 Submission: Submit the form using
SubmitForm(FormName).🔸 Retrieval: Use
FormName.LastSubmit.IDto access the ID of the last submitted record.
🎉 Result
You have a straightforward method to retrieve essential details of records right after they are created or updated, facilitating seamless workflows and enhanced app functionalities.
🌟 Key Advantages
🔸 Streamlined Workflows: Quickly access new or updated record details, allowing for immediate follow-up actions.
🔸 Enhanced User Experience: Provide users with instant feedback or next steps by leveraging the retrieved record details.
🔸 Error Handling: Allows validating the success of record creation or update before proceeding, improving reliability.
🎥 Video Tutorial
🛠️ FAQ
1. How do I retrieve the ID of a newly created record using Patch?
Use a Set variable around your Patch function, for example: Set(NewRecord, Patch(Table, Defaults(Table), {...})), then use NewRecord.ID.
2. Can I use Form.LastSubmit with any form control?
Yes, as long as the form is linked to a data source and you use SubmitForm(FormName), you can access FormName.LastSubmit.
3. What if record creation fails?
Implement error handling by checking if the Patch returns a valid record or use IfError and Notify functions to inform users of failures.
🔗 Related Tips
🔸 #PowerPlatformTip 57: ‘Mastering PATCH’ - the broader Patch techniques this record-details trick builds on.
🔸 #PowerPlatformTip 136: ‘Patch + Coalesce Upsert’ - wrap the same variable-around-Patch idea around a combined create-or-update call.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).