Dynamics 365 Business Central: How to set Company Badge (System Indicator) via AL Code – Automatically set Company Badge

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to set Company Badge (System Indicator) via AL Code – Automatically set Company Badge.

If your Business Central includes multiple companies, your users might want to use company badges to help them quickly identify and keep track of which company they’re currently working in. For more information, see Display a company badge.

On the Company Information page, you can replace the standard company icon with a custom badge on a per-company basis. A company badge can make it easier to identify the company you’re working in.

On the Company Badge FastTab, fill in the fields as necessary. Hover over a field to read a short description.

When done, refresh the browser (select Ctrl+F5) to update the badge in the client.

Done.
Tip: A company badge also indicates the type of environment the company is in. A round company badge signifies a production environment, and a square badge signifies a sandbox environment.

More details: Business Central 2022 wave 2 (BC21): New Company Badge (System Indicator)

So, can this Company Badge (System Indicator) be set automatically? Yes, of course. In this post, I’ll share a simple method to set the Company Badge (System Indicator) without modifying the data in the Company Information table (79).

This time we need to use the following codeunit and method.

codeunit 2000000004 “UI Helper Triggers” : Provides business events for extending UI helper functionality including auto-formatting, caption translation, system indicators, and application language management.

procedure GetSystemIndicator(): Business event that allows subscribers to provide custom system indicator text and styling.

Let’s look at a simple example.
Text=CompanyName
Stype=Accent6

Test code:

codeunit 50112 EventHandlers
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"UI Helper Triggers", GetSystemIndicator, '', false, false)]
    local procedure "UIHelperTriggers_GetSystemIndicator"(var Text: Text[250]; var Style: Option)
    var
        SystemIndicatorStyle: Option Standard,Accent1,Accent2,Accent3,Accent4,Accent5,Accent6,Accent7,Accent8,Accent9;
    begin
        Text := CompanyName;
        Style := SystemIndicatorStyle::Accent6;
    end;
}

Let’s look at a slightly more complex example. Set different Company Badges based on the company name.

Test code:

codeunit 50112 EventHandlers
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"UI Helper Triggers", GetSystemIndicator, '', false, false)]
    local procedure "UIHelperTriggers_GetSystemIndicator"(var Text: Text[250]; var Style: Option)
    var
        SystemIndicatorStyle: Option Standard,Accent1,Accent2,Accent3,Accent4,Accent5,Accent6,Accent7,Accent8,Accent9;
    begin
        case CompanyName of
            'My Company':
                begin
                    Text := 'My';
                    Style := SystemIndicatorStyle::Accent1;
                end;
            'ZY':
                begin
                    Text := 'ZY';
                    Style := SystemIndicatorStyle::Accent2;
                end;
            'Demo':
                begin
                    Text := 'Demo';
                    Style := SystemIndicatorStyle::Accent3;
                end;
            'Demo 02':
                begin
                    Text := 'Demo2';
                    Style := SystemIndicatorStyle::Accent4;
                end;
            'Demo 03':
                begin
                    Text := 'Demo3';
                    Style := SystemIndicatorStyle::Accent5;
                end;
        end;
    end;
}

As for the values ​​of the Style Option, you can refer to the table below.

StyleOption
Dark BlueStandard
Light BlueAccent1
Dark GreenAccent2
Light GreenAccent3
Dark YellowAccent4
Light YellowAccent5
RedAccent6
OrangeAccent7
Deep PurpleAccent8
Bright PurpleAccent9

It’s a straightforward approach that allows you to dynamically set the Company Badge based on specific logic. Give it a try!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL