How to change the font color in Business Central?

isabtogumonisabtogumon Member Posts: 46
Hello everyone,
Is it possible to change the color of the font, as shown in the image? In this example the font color changed because the invoice expired. How can I change the font color to yellow five days before the document expires?

bva5lh8m8953.jpg

Best Answer

Answers

  • DenSterDenSter Member Posts: 8,307
    One of those things that are on my list to figure out but haven't gotten to yet. I don't know exactly how it works for conditional formatting but it has something to do with the Style and StyleExpr properties on page objects.

    Maybe this will get you started:
    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-style-property
  • ResolusResolus Member Posts: 40
    I have only tried it in the windows client and it works there.

    As DenSter already mentioned it has to do with the Style and StyleExpr properties that the fields on a page have.

    I created a global variable "TxtStyleExpr" of type Text with no length.

    On the page, I put that variable, "TxtStyleExpr" in the property "StyleExpr" leaving "Style" on <none>.

    Then in code I use that text variable in the OnAfterGetRecord:
    TxtStyleExpr := 'Standard'; // Default
    
    IF (BooOrderExpired) THEN
      TxtStyleExpr := 'Unfavorable'; // Bold Red
    
    IF (BooOrder5DayNotice) THEN
      TxtStyleExpr := 'Ambiguous'; // Orange
    

    You can only use the styles that are defined by Microsoft.
    The URL that DenSter provided has a list that defines them.
  • isabtogumonisabtogumon Member Posts: 46
    Resolus wrote: »
    I have only tried it in the windows client and it works there.

    As DenSter already mentioned it has to do with the Style and StyleExpr properties that the fields on a page have.

    I created a global variable "TxtStyleExpr" of type Text with no length.

    On the page, I put that variable, "TxtStyleExpr" in the property "StyleExpr" leaving "Style" on <none>.

    Then in code I use that text variable in the OnAfterGetRecord:
    TxtStyleExpr := 'Standard'; // Default
    
    IF (BooOrderExpired) THEN
      TxtStyleExpr := 'Unfavorable'; // Bold Red
    
    IF (BooOrder5DayNotice) THEN
      TxtStyleExpr := 'Ambiguous'; // Orange
    

    You can only use the styles that are defined by Microsoft.
    The URL that DenSter provided has a list that defines them.

    I have used your example, it did not go well, the font color has not changed, this is the code I have written
    trigger OnAfterGetRecord();
        begin
            MyStyleExpr := 'Standard';
            if ("Document No." = 'FVR00043') then
                MyStyleExpr := 'Ambiguous';
        end;
    
        var
            MyStyleExpr: Text;
    

    Can you tell me what I need to make it work well?
  • DenSterDenSter Member Posts: 8,307
    Works for me:
    isopwkyrbptx.png

    Did you set the StyleExpr property to your MyStyleExpr variable? I set it at a field level. In the screenshot you see that only No and Name are formatted, those are the fields that I set the StyleExpr property.
  • isabtogumonisabtogumon Member Posts: 46
    Thanks DenSter,

    I added the property to the field and it worked, I consider that was what was missing. I did it this way, could you tell me if it is the right way?
        layout
        {
            // Add changes to page layout here
            modify("Document No.")
            {
                StyleExpr = MyStyleExpr;
            }
            modify("Document Type")
            {
                StyleExpr = MyStyleExpr;
            }
        }
        var
            MyStyleExpr: Text;
    
        trigger OnAfterGetRecord();
        begin
            MyStyleExpr := 'Standard';
            if ("Document No." = 'FVR00043') then
                MyStyleExpr := 'Ambiguous';
        end;
    
Sign In or Register to comment.