Page style should not use string literal
AL developers commonly assign string literals like 'Unfavorable' to a StyleExpr variable to control page field styling at runtime, or store them in locked label constants for reuse. A misspelling — 'Unfavourable' — compiles without error but silently produces no styling, because the runtime does not recognize the value.
Since Business Central 2024 Wave 2 (BC25), the PageStyle
datatype provides IntelliSense and compile-time checking. Use Format(PageStyle::Value) instead of string literals.
Example
The StyleExpr property on page fields accepts a text variable that controls the field’s style at runtime. This pattern commonly uses string literals:
page 50100 MyPage
{
layout
{
area(Content)
{
field(Amount; Rec.Amount)
{
StyleExpr = AmountStyle;
}
}
}
var
AmountStyle: Text;
trigger OnAfterGetRecord()
begin
AmountStyle := 'Unfavorable'; // Page style should not use string literal [LC0086]
end;
}Use Format(PageStyle::Value) to get compile-time validation:
page 50100 MyPage
{
layout
{
area(Content)
{
field(Amount; Rec.Amount)
{
StyleExpr = AmountStyle;
}
}
}
var
AmountStyle: Text;
trigger OnAfterGetRecord()
begin
AmountStyle := Format(PageStyle::Unfavorable);
end;
}Locked labels are also used to store style values for reuse. This pattern triggers the rule as well:
codeunit 50100 MyCodeunit
{
var
UnfavorableTok: Label 'Unfavorable', Locked = true; // Page style should not use string literal [LC0086]
}Replace the locked label with a procedure that returns the formatted value:
codeunit 50100 MyCodeunit
{
procedure GetUnfavorableStyle(): Text
begin
exit(Format(PageStyle::Unfavorable));
end;
}When the diagnostic is reported
The rule uses case-sensitive matching. Only PascalCase values matching the exact PageStyle enum names are flagged:
| Literal | Flagged | Reason |
|---|---|---|
'Standard' | Yes | Exact match to PageStyle::Standard |
'STANDARD' | No | All-caps convention indicates a data constant |
'standard' | No | Lowercase indicates a data constant |
Valid PageStyle values: None, Standard, StandardAccent, Strong, StrongAccent, Attention, AttentionAccent, Favorable, Unfavorable, Ambiguous, Subordinate.
Exception
The rule suppresses the diagnostic when the string literal appears in a context where it represents data or user-facing text rather than a style value:
- Caption properties:
Caption = 'Standard'is user-facing text - Unlocked labels:
Label 'Unfavorable'withoutLocked = trueis translatable text - StyleExpr property values:
StyleExpr = 'Standard'already uses the string in the correct property - Enum and enum value definitions: string literals in enum contexts are identifiers
- Table field assignments and data-access method arguments: writes to data on
Record,RecordRef,FieldRef,Query, and similar types
In rare cases, a PascalCase string literal genuinely represents data — for example, a locked label 'Standard' used as a configuration value. Use a pragma directive to suppress the diagnostic:
codeunit 50100 MyCodeunit
{
var
#pragma warning disable LC0086
ConfigValueTok: Label 'Standard', Locked = true; // configuration value, not a page style
#pragma warning restore LC0086
}See also
- PageStyle Data Type on Microsoft Learn