Business Central 2024 wave 2 (BC25): new data type PageStyle

Dynamics 365 Business Central

Hi, Readers.
The public preview for Dynamics 365 Business Central 2024 release wave 2 (BC25) is available. Learn more: Link.

I will continue to test and share some new features that I hope will be helpful.

In this post, I would like to talk about new type PageStyle in Business Central 2024 release wave 2 (BC25). This is not yet documented in the Business Central 2024 release wave 2 (BC25) release plan. But it is mentioned in AL Language extension changelog Version 14.0

The type can be used to get the valid values for StyleExpr, found on page controls. Here is an example of how to use it:

layout
{
    area(Content)
    {
        field(Name; rec.Name)
        {
            StyleExpr = nameStyle;
        }
    }
}

var nameStyle : Text;

local procedure ChangeNameStyle(newPageStyle : PageStyle)
begin
    nameStyle := format(newPageStyle);
end;
https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

For example,

Microsoft hasn’t provided much information about this new data type yet. Here’s my current understanding, I hope it helps.

As you know, in Business Central, we can control the color and font displayed on the page through the following two properties.

Style Property: Sets a value that determines how text in a field on a page is formatted.

ValueAvailable or changed withDescription
Noneruntime version 1.0None
Standardruntime version 1.0Standard
StandardAccentruntime version 1.0Blue
Strongruntime version 1.0Bold
StrongAccentruntime version 1.0Blue + Bold
Attentionruntime version 1.0Red + Italic
AttentionAccentruntime version 1.0Blue + Italic
Favorableruntime version 1.0Bold + Green
Unfavorableruntime version 1.0Bold + Italic + Red
Ambiguousruntime version 1.0Yellow
Subordinateruntime version 1.0Grey

StyleExpr Property: Sets whether the format that is specified in the Style Property is applied to text in a field.

For example, in the standard Customer Ledger Entries, the Due Date is used to determine the font/color displayed on the page.

We also discussed a similar topic before, more details: Change field color based on field value in Dynamics 365 Business Central

You can find that whether it is Microsoft documentation, BC standard code, or my example, the value of StyleExpr Property is hard-coded. This will not work if we misspell the text, Unfavorable, Ambiguous or etc.

Well, this has changed in this wave (BC25), new data type PageStyle. You can see that this data type contains all 11 values ​​in the Style Property.

This type looks like an Enum or Option type internally.

PS:

Cannot implicitly convert type ‘PageStyle’ to ‘Text’AL AL0122

So now we can easily do the following.

Test video:

Great, give it a try!!!😁

Test code:

pageextension 50100 ItemListExt extends "Item List"
{
    layout
    {
        modify(Description)
        {
            StyleExpr = nameStyle;
        }
    }
    actions
    {
        addafter(AdjustInventory)
        {
            action(StandardAccent)
            {
                ApplicationArea = All;
                Caption = 'StandardAccent';
                Image = Change;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                begin
                    ChangeNameStyle(PageStyle::StandardAccent);
                end;
            }
            action(Strong)
            {
                ApplicationArea = All;
                Caption = 'Strong';
                Image = Change;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                begin
                    ChangeNameStyle(PageStyle::Strong);
                end;
            }
            action(Favorable)
            {
                ApplicationArea = All;
                Caption = 'Favorable';
                Image = Change;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                begin
                    ChangeNameStyle(PageStyle::Favorable);
                end;
            }
            action(Ambiguous)
            {
                ApplicationArea = All;
                Caption = 'Ambiguous';
                Image = Change;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                begin
                    ChangeNameStyle(PageStyle::Ambiguous);
                end;
            }
        }
    }

    var
        nameStyle: Text;

    local procedure ChangeNameStyle(newPageStyle: PageStyle)
    begin
        nameStyle := Format(newPageStyle);
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL