PageVariable.SetRecord() cannot use a temporary record for the Record parameter. #611
christianbraeunlich
started this conversation in
New Rule
Replies: 1 comment 1 reply
-
Valid point you're making. If I understand correctly, it's kinda like the (simplefied) scenario below? This indeed doesn't work as expected and returns another customer records it seems. It seems there's no rule in one of the Code Analyzers for this. Seems doable to create an rule for this. pageextension 50100 "Customer List" extends "Customer List"
{
actions
{
addafter(WordTemplate)
{
action(SetRecordWithTempTable)
{
ApplicationArea = All;
Caption = 'Set Record with TempTable';
trigger OnAction()
var
TempCustomer: Record Customer temporary;
CustomerCard: Page "Customer Card";
begin
TempCustomer.Init();
TempCustomer."No." := '12345';
TempCustomer."Name" := 'Set Record with TempTable';
TempCustomer.Insert(false);
CustomerCard.SetRecord(TempCustomer);
CustomerCard.Run();
end;
}
}
}
} Regarding your addition, about passing an entire table, I'm assuming the best pratice would be that the table variable contains one (single) record? That's easy to determine in runtime, but difficult to determine in the compiler. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello there,
the goal of this rule is to deal with the record parameter of the PageVariable.SetRecord() procedure which cannot use a temporary record for the Record parameter.
Stated in the docs (see: https://learn.microsoft.com/de-de/dynamics365/business-central/dev-itpro/developer/methods-auto/page/page-setrecord-method#parameters): "Record: The record to set as the current record. You cannot use a temporary record for the Record parameter."
In addition, I sometimes see that this method is used to set the entire table of the page. However, this is not the case because "You can use this method to set the record to display when the user opens the page.".
Any additional thoughts on this? Is there already a rule I haven't found yet?
Beta Was this translation helpful? Give feedback.
All reactions