Page style should not use string literal

Properties
LC0086 Warning Design Code Fix Ignore Obsolete

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:

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

Valid PageStyle values: None, Standard, StandardAccent, Strong, StrongAccent, Attention, AttentionAccent, Favorable, Unfavorable, Ambiguous, Subordinate.

Exception

The rule applies one fixed set of contexts to every PageStyle value, so you can tell from the code alone whether a literal is reported. It does not report a string literal that represents data or user-facing text rather than a style value:

  • Method and attribute arguments: any call, built-in or your own, such as SetRange(Code, 'None'), StrSubstNo('%1', 'Standard') or Assert.AreEqual('Strong', ...), and attribute arguments such as an event name in [EventSubscriber(...)]
  • Comparisons: operands of =, <>, <, <=, >, >= and elements of an in [...] list, also in parentheses, as part of a range, or as a branch of a ? : expression
  • Case labels: 'None': or 'Attention'..'Unfavorable': (a literal in the statement after the label is still reported)
  • Property values: Caption = 'Standard', Description = 'Standard', and also StyleExpr = 'Standard', which already uses the string in the correct property
  • Unlocked labels and report labels: Label 'Unfavorable' or StandardType = 'Standard'; in a report’s labels section without Locked = true is translatable text
  • Multilanguage text: TextConst ENU = 'Standard' and the legacy label(StandardType; ENU = 'Standard') report label, which have no Locked option
  • Enum and enum value definitions: string literals in enum contexts are identifiers
  • Table field assignments: Customer.Name := 'Standard' writes data

Assignments to other variables (including array elements and both branches of a ? : expression), exit('...'), and locked labels or report labels are reported. A style value passed to a helper method as an argument, such as SetStyle('Unfavorable'), is not reported.

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