Post

#PowerPlatformTip 79: 'Retrieve Record Details Post-Update'

#PowerPlatformTip 79: 'Retrieve Record Details Post-Update'

TL;DR: Patch returns the created or updated record, so Set(varNew, Patch(...)) gives you its ID right away. For an Edit form, read Self.LastSubmit in the form’s OnSuccess, not in the button after SubmitForm. The ID column is ID in SharePoint, and in Dataverse it’s the table’s unique identifier column (for Accounts: Account). Wrap Patch in IfError so a failed save doesn’t continue with an empty record.

💡 Challenge

After saving, you often need the new record right away: its ID for a child record, a flow call or a confirmation message. Reading it back with a LookUp costs an extra call and can pick the wrong row.

✅ Solution

Use what the save already returns. Patch returns the record as the data source stored it, including server-generated columns. The Edit form exposes the same record in its LastSubmit property once the submit has succeeded.

🔧 How It’s Done

1. Patch: store the returned record

🔸 SharePoint:

1
2
Set(varNew, Patch(Products, Defaults(Products), {Title: "New Product"}));
Notify("Created item " & varNew.ID, NotificationType.Success)

🔸 Dataverse: there’s no ID column. Use the table’s unique identifier column, which carries the table’s singular name, for example varNew.Account for the Accounts table or varNew.Product for a custom Products table.

2. Patch with error handling

1
2
3
4
5
IfError(
    Set(varNew, Patch(Products, Defaults(Products), {Title: "New Product"})),
    Notify("Saving failed: " & FirstError.Message, NotificationType.Error),
    Navigate(scrDetail)
)

🔸 If Patch fails, the second argument runs and the app doesn’t navigate with an empty varNew.

3. Edit form: read LastSubmit in OnSuccess

🔸 Button OnSelect: SubmitForm(frmProduct)

🔸 Form OnSuccess:

1
2
Set(varNew, Self.LastSubmit);
Notify("Saved item " & Self.LastSubmit.ID, NotificationType.Success)

🔸 OnSuccess runs only after the data source has confirmed the save, so LastSubmit is guaranteed to hold the record you just saved. If validation or the save fails, OnSuccess doesn’t run and nothing continues with a stale record.

🔸 Use the form’s OnFailure with Self.Error for the error message.

4. Use the record for the next step

🔸 Child record: Patch(OrderLines, Defaults(OrderLines), {OrderID: varNew.ID, Title: "Line 1"})

🔸 Flow call: MyFlow.Run(varNew.ID)

🎉 Result

You get the saved record, including server-generated values such as the ID, created date and calculated columns, without a second query, and only after the save actually succeeded.

🌟 Key Advantages

🔸 No extra query: the save returns the record.

🔸 Server values included: ID, created date and calculated columns are filled.

🔸 Safe sequence: IfError and OnSuccess prevent follow-up actions on a failed save.

🔸 Works for create and update: Patch returns the updated record too.

🎥 Video Tutorial

🛠️ FAQ

1. How do I retrieve the ID of a newly created record using Patch?

Store the result: Set(varNew, Patch(Table, Defaults(Table), {...})), then read varNew.ID in SharePoint or the unique identifier column (for example varNew.Account) in Dataverse.

2. Why does LastSubmit sometimes show an older record?

LastSubmit holds the last record that was submitted successfully. If the current submit failed validation or the save, it still shows the previous one. Read Self.LastSubmit in OnSuccess, which only runs after a successful save.

3. What if record creation fails?

Wrap Patch in IfError and show FirstError.Message. For forms, use OnFailure and the form’s Error property.

🔸 #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).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.