Record.Get procedure arguments (PC0013)
Validates that calls to the Get procedure on Record objects use the correct number, types, and order of arguments matching the table’s primary key. Providing insufficient arguments, too many arguments, or arguments of the wrong type can cause runtime errors or unexpected behavior.
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;
Integercan be converted toOptionand/orBigIntegerBigIntegercan be converted toDurationCodecan be converted toTextTextcan be converted toCodeString(literal)can be converted toTextand/orCode
Integer to Enum
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;
Enum to Option
To convert an Enum to an Option, use the AsInteger() method on the Enum object.
procedure MyProcedure(MyObjectType: Enum MyObjectType; ObjectId: Integer)
var
AllObjWithCaption: Record AllObjWithCaption;
begin
AllObjWithCaption.Get(MyObjectType.AsInteger(), ObjectId);
end;
By requiring applying the AsInteger(), it’s explicit that you’re intentionally converting an Enum to an Option value. This avoids accidental conversions and makes it clear in the code that this action is intentional and not a mistake or implicit behavior.