Using a variable to drive OnFormat in Form field

jversusjjversusj Member Posts: 489
Hello,
I searched the forum and didn't find this exact topic.

I am trying to format text on a sales lines to a different color based on a variable I am defining in the OnAfterGetCurrRecord trigger. I am essentially creating a visual cue to a user looking at an order to see if there is a problem on a line.

I set a boolean flag based on a condition in the OnAfterGetCurrRecord.
Then on the OnFormat trigger of the related field, I have code that says, if the boolean is true, make purple and bold, otherwise it is normal text formatting.

When i watch through debugger, my code behaves as i would expect. my flag is set properly, and the correct condition is followed OnFormat. Trouble is, the final result is no color being displayed on the sales line.

If i refer to an actual field on the sales line, my conditional formatting works (for example, if type = Item, make item no. = purple), yet trying to leverage a variable does not. I do not want to add a field to the sales line for this - what might i be doing wrong?
kind of fell into this...

Answers

  • jversusjjversusj Member Posts: 489
    okay - i think i solved this. I had to add a CLEAR in my filters that ultimately lead to my condition being true.
    kind of fell into this...
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Better create two global variables: say gColor - integer and gBold - Boolean.

    Then in each required field in OnFormat triggr write two lines of code:
    CurrForm."field name".UPDATEFORECOLOR(gColor);
    CurrForm."field name".UPDATEFONTBOLD(gBold);
    
    then all you need to do is in OnAfterGetRecord assign proper values to your variables.

    If you do your code in OnAfterGetCurrRecord only current line will have desired values, and the rest will be more-less randomly colored. If you need to color only current line CLEAR both variables in OnAfterGetRecord.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.