LC0075 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki
.Get()
method on Record object.
Incorrect number or type of arguments in This rule ensures that calls to the built-in GET
procedure on Record
objects have the correct number, types, and order of arguments matching the primary key of the record in question.
Incorrect usage, such as providing insufficient arguments, too many arguments, or arguments of invalid types, can lead to runtime errors or unexpected behavior. This diagnostic helps developers catch these issues at compile time, making the code safer and more predictable.
Example
procedure GetItemVariant()
var
ItemVariant: Record "Item Variant";
begin
// Invalid arguments in .Get() method for record "Item Variant": Insufficient arguments provided; expected 2 arguments.
ItemVariant.Get('10000');
end;
procedure GetSalesHeader(DocumentId: Integer)
var
SalesHeader: Record "Sales Header";
begin
// Invalid arguments in .Get() method for record "Sales Header": Argument at position 2 has an invalid type; expected 'Code[20]', found 'Integer'.
SalesHeader.Get("Sales Document Type"::Order, DocumentId);
end;
procedure GetCompanyInformation()
var
CompanyInformation: Record "Company Information";
begin
// Invalid arguments in .Get() method for record "Company Information": Too many arguments provided; expected 1 arguments.
CompanyInformation.Get('', 12345);
end;
Exceptions
procedure GetCompanyInformation()
var
CompanyInformation: Record "Company Information";
begin
// If a table has one single Primary Key field of type Code, it's probably a setup table with the Singleton pattern, where we allow a GET without parameters
CompanyInformation.Get();
end;
procedure GetItemVariant(MyRecordId: RecordId)
var
ItemVariant: Record "Item Variant";
begin
// RecordId object is populated on runtime, no diagnostics executed
ItemVariant.Get(MyRecordId);
end;
Implicit conversions
During analyzing the correct type of the argument, the following implicit conversions are allowed;
Integer
can be converted toOption
and/orBigInteger
BigInteger
can be converted toDuration
Code
can be converted toText
Text
can be converted toCode
String(literal)
can be converted toText
and/orCode
To convert an Integer
to an Enum
use the FromInteger
method on the Enum object
procedure GetSalesHeader(DocumentTypeAsInteger: Integer; DocumentNo: Code[20])
var
SalesHeader: Record "Sales Header";
begin
SalesHeader.Get("Sales Document Type".FromInteger(DocumentTypeAsInteger), DocumentNo);
end;