Page style should not use string literal (LC0086)

Since Business Central 2024 Wave 2 (BC25), the PageStyle datatype provides a typed alternative to string literals for page styling. String literals like 'Unfavorable' lack IntelliSense support and produce no compile-time error when misspelled.

This rule flags string literals that match a PageStyle value name (case-sensitive, PascalCase only). Valid values are: None, Standard, StandardAccent, Strong, StrongAccent, Attention, AttentionAccent, Favorable, Unfavorable, Ambiguous, and Subordinate.

Example: StyleExpr variable assignment

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'; // LC0086: Avoid using the string literal 'Unfavorable'
    end;
}

To fix this, use Format(PageStyle::Value):

page 50100 MyPage
{
    layout
    {
        area(Content)
        {
            field(Amount; Rec.Amount)
            {
                StyleExpr = AmountStyle;
            }
        }
    }

    var
        AmountStyle: Text;

    trigger OnAfterGetRecord()
    begin
        AmountStyle := Format(PageStyle::Unfavorable);
    end;
}

Example: Locked label constant

Locked labels are often used to store style values for reuse. This pattern also triggers the rule:

codeunit 50100 MyCodeunit
{
    var
        UnfavorableTok: Label 'Unfavorable', Locked = true;
}

Use a PageStyle variable instead:

codeunit 50100 MyCodeunit
{
    procedure GetUnfavorableStyle(): Text
    begin
        exit(Format(PageStyle::Unfavorable));
    end;
}

Case sensitivity

The rule uses case-sensitive matching. Only PascalCase values matching the exact PageStyle enum names are flagged. This means:

LiteralFlaggedReason
'Standard'YesExact match to PageStyle::Standard
'STANDARD'NoAll-caps convention indicates a data constant
'standard'NoLowercase indicates a data constant

When the rule does not trigger

The rule suppresses the diagnostic in the following contexts:

  • Caption properties: Caption = 'Standard' is user-facing text, not a style value
  • Unlocked labels: Label 'Unfavorable' without Locked = true is 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: MyRecord.MyField := 'Standard' writes to data, not styling
  • Data-access method arguments: String literals passed to methods on Record, RecordRef, FieldRef, Query, and similar types

Suppressing rare false positives

In rare cases, a PascalCase string literal may match a style name but genuinely represent 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;
#pragma warning restore LC0086
}

See also