LC0088 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki
Option types should be avoided, use enum if applicable.
Option types should be avoided to get rid of some of the bad patterns that come along with option fields.
Example
field(120; Status; Option)
{
Caption = 'Status';
OptionMembers = Open,Released,"Pending Approval","Pending Prepayment";
}
In stead of using a Option type, it's best pratice to use a Enum object.
field(120; Status; Enum Status)
{
Caption = 'Status';
}
enum 50100 Status
{
value(0; Open) { }
value(1; Released) { }
value(2; "Pending Approval") { }
value(3; "Pending Prepayment") { }
}
Exceptions
In the example below the rule won't raise a diagnostic, where it could be a valid choice for an Option type. An unwanted side effect could be that the code is changed to an integer, like ReservationManagement.SetItemTrackingHandling(1);
, where the code is then less readable.
internal procedure DeleteReservEntries()
var
ReservationManagement: Codeunit "Reservation Management";
Mode: Option "None","Allow deletion",Match;
begin
ReservationManagement.SetReservSource(Rec);
ReservationManagement.SetItemTrackingHandling(Mode::"Allow deletion");
ReservationManagement.DeleteReservEntries(true, 0);
end;
The rule excluded tables with specific TableType property set to CDS.
The AL Table Proxy Generator converts an OptionSet from Dataverse to an Option type to Business Central. See the statecode field in the example below.
table 50100 "Dataverse Project PTE"
{
ExternalName = 'prefix_project';
TableType = CDS;
Caption = 'Project';
fields
{
field(1; prefix_projectId; Guid)
{
ExternalName = 'prefix_projectid';
ExternalType = 'Uniqueidentifier';
ExternalAccess = Insert;
Description = 'Unique identifier for entity instances';
Caption = 'Project';
}
field(2; prefix_name; Text[100])
{
ExternalName = 'prefix_name';
ExternalType = 'String';
Description = 'The name of the custom entity.';
Caption = 'Name';
}
field(25; statecode; Option)
{
ExternalName = 'statecode';
ExternalType = 'State';
ExternalAccess = Modify;
Description = 'Status of the Project';
Caption = 'Status';
InitValue = " ";
OptionMembers = " ",Active,Inactive;
OptionOrdinalValues = -1, 0, 1;
}
}
}