SetRecord() does not show the data of a temporary record
Page.SetRecord() sets the current record of a page by its primary key. It does not hand the record’s data to the page: the page still reads its records from its own source and only positions itself on that key. When the page’s source is a database table, a temporary record passed to SetRecord() can never be shown. The page looks the key up in the database, finds nothing or a different record, and silently opens on whatever it found.
Microsoft Learn states “You cannot use a temporary record for the Record parameter” on Page.SetRecord(var Record) Method . There is no runtime error, and the call is valid when the page itself holds temporary data (see the exceptions below). The rule therefore only reports a temporary record passed to a page that reads from the database.
The record counts as temporary when its variable carries the temporary keyword or when its table has TableType = Temporary.
Example
procedure ShowCustomer()
var
TempCustomer: Record Customer temporary;
CustomerCard: Page "Customer Card";
begin
TempCustomer.Init();
TempCustomer."No." := 'TEMP001';
TempCustomer.Insert(false);
CustomerCard.SetRecord(TempCustomer); // SetRecord() does not show the data of a temporary record [PC0036]
CustomerCard.Run();
end;The Customer Card reads from the Customer table, so the page never shows TEMP001 and opens on another customer instead.
To show temporary data on a page over a database table, open the page with Page.Run() or Page.RunModal() and the temporary record:
procedure ShowCustomers()
var
TempCustomer: Record Customer temporary;
begin
TempCustomer.Init();
TempCustomer."No." := 'TEMP001';
TempCustomer.Insert(false);
Page.RunModal(Page::"Customer List", TempCustomer);
end;To position a database-backed page on an existing record, pass a record that was read from the database:
procedure ShowCustomer(CustomerNo: Code[20])
var
Customer: Record Customer;
CustomerCard: Page "Customer Card";
begin
Customer.Get(CustomerNo);
CustomerCard.SetRecord(Customer);
CustomerCard.Run();
end;Exceptions
The diagnostic is not reported when the page holds temporary data itself, because SetRecord() then selects a record the page loads on its own:
- The page declares
SourceTableTemporary = true. - The page’s source table has
TableType = Temporary. - The page declares an
OnFindRecordtrigger, which replaces the data source with the page’s own records.
This is the pattern Microsoft’s own code uses, for example in the Dataverse option lookups: the page loads its records, and SetRecord() preselects one of them.
procedure LookupPaymentTerm(OptionId: Integer): Boolean
var
CRMPaymentTerms: Record "CRM Payment Terms";
CRMPaymentTermsList: Page "CRM Payment Terms List";
begin
// The page has SourceTableTemporary = true and a LoadRecords() procedure that fills Rec.
CRMPaymentTermsList.LoadRecords();
CRMPaymentTerms := CRMPaymentTermsList.GetRec(OptionId);
if CRMPaymentTerms."Option Id" <> 0 then
CRMPaymentTermsList.SetRecord(CRMPaymentTerms);
CRMPaymentTermsList.LookupMode(true);
exit(CRMPaymentTermsList.RunModal() = Action::LookupOK);
end;Page.Run(), Page.RunModal(), GetRecord(), SetTableView() and SetSelectionFilter() are never reported: they either accept temporary records by design or do not position the page.
See also
- Temporary Tables on Microsoft Learn
- Page.Run(Integer [, Record] [, Any]) Method on Microsoft Learn
- Page.RunModal(Integer [, Record] [, Any]) Method on Microsoft Learn