LC0075 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki

Incorrect number or type of arguments in .Get() method on Record object.

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 to Option and/or BigInteger
  • BigInteger can be converted to Duration
  • Code can be converted to Text
  • Text can be converted to Code
  • String(literal) can be converted to Text and/or Code

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;

Read more: