Customized captions at run-time without changing Codeunit 1

krikikriki Member, Moderator Posts: 9,094
edited 2011-05-16 in NAV Tips & Tricks
If you want to use customized captions on a field, mostly you change Codeunit 1 to do it. I found a way to use customized captions without changing Codeunit 1.

In the CaptionClass Property you have to put '1,5,,' + txtMyCaption. Or you can also put a function that returns the string.

Some explanation:
The first parameter says it is a dimension
The second parameter says to use a certain format (= optional parameter 1 + dimension caption + optional parameter 2) of the dimension-code (not value-code!) put in parameter 3.
The third parameter is the dimension-code you want. This parameter must contain a value that does not exist in the dimensions (a blank for example). If this dimension does not exists, codeunit 1 shows the fourth parameter on the caption.
The fourth parameter : the value you want to show as caption.
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Comments

  • ajhvdbajhvdb Member Posts: 672
    Thx, never read this tip. But gonna try it out.
  • ajhvdbajhvdb Member Posts: 672
    In the properties of the table I can only work with static values like:
    '3,new caption'
    and ctrl-f8 worked.


    In the form it was more variable.

    In the data properties of a field set it to '3,' + txtMyCaption

    In the OnInit of the form do:
    txtMyCaption := 'New caption';

    and ctrl-f8 still uses the old caption, but for me this was good enough, thx
  • lyotlyot Member Posts: 202
    Doesn't work for me at all :?
    Nav 5.0. SP1
  • krikikriki Member, Moderator Posts: 9,094
    lyot wrote:
    Doesn't work for me at all :?
    Nav 5.0. SP1
    Just tried this '1,5,,' + 'kriki' in the Captionclass of a 5.0SP1W1 and it works. It shows 'kriki' in the caption.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • lyotlyot Member Posts: 202
    If I modify this in the CaptionClass property of the field on the form, nothing changes... :cry:

    If I modify this in the CaptionClass property of the field on the table...
    then I have even stranger things...
    A first look shows me that nothing changed... but when I do a Zoom on the form (CTRL+F8 ) and I choose to show columns field & fieldname.
    Field is blank and fieldname contains "inventory"

    Strange, strange,... ](*,)
  • XypherXypher Member Posts: 297
    Make sure to use...
    CurrForm.UPDATECONROLS;
    

    Everytime you change '1,5,,' + YourVariable's value !

    I was fumbling on this and it just didn't seem to work until I finally tried UPDATECONTROLS. :|


    Thank you kriki :)
  • AntidotEAntidotE Member Posts: 61
    sorry for necroposting, but this helped me a lot and I would like to share my researches!
    6.0 SP1 - still works for classic!
    small example is below
    made small list form to show dynamic caption fo Net Weight as "1 <base unit of measure> of <description> will weight" and values is lower:
    OBJECT Form 50000 Test Dynamic Caption
    {
      OBJECT-PROPERTIES
      {
        Date=16.05.11;
        Time=17:37:58;
        Modified=Yes;
        Version List=by AntidotE for Mibuso.com;
      }
      PROPERTIES
      {
        Width=12210;
        Height=5940;
        TableBoxID=50000;
        SourceTable=Table27;
        OnAfterGetCurrRecord=BEGIN
                               BUoM := "Base Unit of Measure";
                               Desc := COPYSTR(Description,1,30);
                               CurrForm.UPDATECONTROLS;
                             END;
    
      }
      CONTROLS
      {
        { 50000;TableBox    ;220  ;220  ;11770;5500 ;HorzGlue=Both;
                                                     VertGlue=Both;
                                                     HeadingHeight=880 }
        { 50001;TextBox     ;0    ;0    ;1700 ;0    ;ParentControl=50000;
                                                     InColumn=Yes;
                                                     SourceExpr="No." }
        { 50002;Label       ;0    ;0    ;0    ;0    ;ParentControl=50001;
                                                     InColumnHeading=Yes }
        { 50003;TextBox     ;0    ;0    ;3090 ;0    ;HorzGlue=Both;
                                                     ParentControl=50000;
                                                     InColumn=Yes;
                                                     SourceExpr=Description }
        { 50004;Label       ;0    ;0    ;0    ;0    ;ParentControl=50003;
                                                     InColumnHeading=Yes }
        { 50009;TextBox     ;7197 ;550  ;1320 ;440  ;ParentControl=50000;
                                                     InColumn=Yes;
                                                     SourceExpr="Base Unit of Measure" }
        { 50010;Label       ;0    ;0    ;0    ;0    ;ParentControl=50009;
                                                     InColumnHeading=Yes }
        { 50007;TextBox     ;0    ;0    ;4290 ;0    ;ParentControl=50000;
                                                     InColumn=Yes;
                                                     SourceExpr="Net Weight";
                                                     CaptionClass=STRSUBSTNO(Text001,BUoM,Desc) }
        { 50008;Label       ;0    ;0    ;0    ;0    ;ParentControl=50007;
                                                     InColumnHeading=Yes }
      }
      CODE
      {
        VAR
          Text001@50000 : TextConst 'ENU=3,1 %1 of %2 will weigh';
          BUoM@50001 : Code[10];
          Desc@50002 : Text[30];
    
        BEGIN
        END.
      }
    }
    

    NB! take into account of limit of result caption length of 80!
    It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.
Sign In or Register to comment.