Very often you have to create a record and fill with the fresh created record id reference tables like logs, events and others. To do so within the power apps, you need to be able to fetch the record(s) which have been created with the latest patch function and access this information.

The simplest scenario is where you create a single line and out of this creation you need to update one reference table:

Clear(PatchedInvoiceDetail); ClearCollect(PatchedInvoiceDetail,Patch('[dbo].[Finance.Wf.InvoiceDetail]', Defaults('[dbo].[Finance.Wf.InvoiceDetail]'), { Account: DropdownAccount.SelectedText.Value, CCCUPJId: DropdownCostCenter.SelectedText.Value, NetAmount: Value(TextInputAmount.Text), InvoiceHeaderId: invoiceRecord.InvoiceHeaderId, CreatedAt: Now(), Status: "rejected" } )); Patch('[dbo].[Finance.Wf.InvoiceResponsible]', Defaults('[dbo].[Finance.Wf.InvoiceResponsible]'), { InvoiceHeaderId: invoiceRecord.InvoiceHeaderId, InvoiceDetailId : First(PatchedInvoiceDetail).InvoiceDetailId, osUser: Office365Users.UserProfile(DropdownEmail.SelectedText.Value).Mail, RoleId: 2, CreatedAt: Now() } )
Code-Sprache: JavaScript (javascript)

The most important step here is that you use the “ClearCollect” function to temporarly store the resultset of the “Patch” function.