web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Color labels on form

(4) ShareShare
ReportReport
Posted on by 217
Hello,
 
Does anyone know how to make a label on a form a different color?
I have the same question (0)
  • Suggested answer
    Jimmy Passeti Profile Picture
    938 Most Valuable Professional on at
    Hello,
     
    Unfortunately, it's not possible to do this natively.
    But you can use components to achieve this, such as this one:
    Custom Label | PCF Gallery
     
    Regards,
    Jimmy Passeti | Microsoft MVP
    ✅ Please mark as Verified if this answered your question!
  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,360 Moderator on at

    AI was used to create this answer
    Yes, you can change the color of a label on a form in Microsoft Dynamics 365 Business Central (BC) using AL code. However, note that the ability to customize colors directly on labels is limited in the base functionality of BC. You can achieve this by using the Style and StyleExpr properties for controls on pages or reports.

    Here’s how you can do it:


    Steps to Change Label Color on a Form:

    1. Open the AL Project:

      • Open your AL project in Visual Studio Code or the development environment you are using.

    2. Locate the Page or Report:

      • Find the page or report where the label is located.

    3. Use the Style and StyleExpr Properties:

      • Use the Style property to define the appearance of the control (e.g., label, field).

      • Use the StyleExpr property to dynamically set the style based on a condition.


    Example: Changing Label Color on a Page

    Here’s an example of how to change the color of a label on a page:

    al
    Copy
    page 50100 "My Custom Page"
    {
        layout
        {
            area(Content)
            {
                field("My Field"; "My Field")
                {
                    ApplicationArea = All;
                    Style = Strong; // Applies a strong (bold) style
                    StyleExpr = ShouldHighlight; // Dynamically applies style based on a condition
                }
                label(MyLabel)
                {
                    ApplicationArea = All;
                    Caption = 'This is a colored label';
                    Style = Favorable; // Applies a green color
                }
            }
        }
    
        var
            ShouldHighlight: Boolean;
    
        trigger OnAfterGetRecord()
        begin
            // Set the condition for dynamic styling
            ShouldHighlight := "My Field" > 100;
        end;
    }

    Available Style Options:

    The Style property supports the following options:

    • Standard: Default style.

    • Strong: Bold text.

    • Attention: Red color (used for warnings or errors).

    • Favorable: Green color (used for positive indicators).

    • Unfavorable: Red color (used for negative indicators).

    • Ambiguous: Yellow color (used for warnings or uncertain states).

    • Subordinate: Gray color (used for less important information).


    Limitations:

    • The Style property is primarily designed for fields, not labels. For labels, you can only use the Style property if the label is part of a field or group.

    • If you need more advanced customization (e.g., custom colors), you may need to use client-side extensions or JavaScript for additional styling.


    Alternative: Use a Field Instead of a Label:

    If you need more flexibility, consider using a field with a Caption instead of a label. Fields support the Style and StyleExpr properties, allowing you to change colors dynamically.


    Example: Using a Field as a Colored Label

    al
    Copy
    field("Dummy Field"; '')
    {
        ApplicationArea = All;
        Caption = 'This is a colored label';
        Editable = false;
        Style = Favorable; // Applies a green color
    }
  • CU31101219-0 Profile Picture
    217 on at
    This custom control doesn't look like it adds color, just allows you to show static text with ability to make it bold and/or italic.
     
    But you can use components to achieve this, such as this one:
    Custom Label | PCF Gallery
  • CU31101219-0 Profile Picture
    217 on at
    I am trying this, but keep getting an error, anyone know why?
     
    function highlightFieldLabels(executionContext) {
        var formContext = executionContext.getFormContext();
        // Target a specific field by logical name (e.g., "firstname")
        var fieldControl = formContext.getControl("syn_marketcodelookup"); // Replace with your field's logical name
        
        // Get the label element by the field's ID
        var labelElement = document.querySelector('label[for="' + fieldControl.getName() + '"]');
        
        if (labelElement) {
            // Apply CSS styles to the field label
            labelElement.style.backgroundColor = "yellow";
            labelElement.style.color = "red";
            labelElement.style.fontWeight = "bold";
        }
    }
     
     
     
    TypeError: Cannot read properties of undefined (reading 'getFormContext')
        at highlightFieldLabels (https://hmedev.crm.dynamics.com/%7b000010308425969%7d/webresources/new_Account_ColorChange:2:40)
        at b._executeFunctionInternal (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:14:1212544)
        at b.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:14:1210978)
        at https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:4:148863
        at i (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:14:99373)
        at re._executeIndividualEvent (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:4:148837)
        at re._executeEventHandler (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:4:145655)
        at Object.execute (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:4:142708)
        at w._executeSyncAction (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:14:560779)
        at w._executeSync (https://content.powerapps.com/resource/uci-infra-bus/scripts/app.18c8b156931e16e9d083bd7ee820dca0.js:14:560506)
    Error Details:
    Event Name: onload
    Function Name: highlightFieldLabels
    Web Resource Name: new_Account_ColorChange
    Solution Name: Active
    Publisher Name: DefaultPublisherorg1939cae2
     
  • Suggested answer
    JeroenS Profile Picture
    50 on at
    Perhaps not exactly what were asking but could be of interest depending on the reason why you would like to use colors.
    If you don't want to use JavaScript or PCF Controls, but you do want to use somehow colors in views, you can use the Power Apps Grid Control.
    This control has a property Enable OptionSet Colors.
    When you are setting colors on your optionset it does look pretty nice.
     
    If have written a blog post about this a while back if you are interested in setting this up:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 130 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 117

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans