Search code examples
labelaxaptax++dynamics-ax-2012

How to insert label in the info with %n - field's values?


I have to stamp to video a simple string, with label and field's values.

I have this code:

 info (strFmt (" @SYS334481: %1 , @SYS4569: %2 " , myTable.AliasUser, myTable.Day) );

I have an output looklike this :

Alias user , Day

I haven't the field's values. I also tried to use this way , but I have a syntax error:

info (strFmt (" "@SYS334481": %1 , "@SYS4569": %2 " , myTable.AliasUser, myTable.Day ));

What is the correct way?


Solution

  • While making a specific label will work, I would prefer the simpler:

    info(strFmt('%1: %2, %3: %4', fieldPname(myTable,AliasUser), myTable.AliasUser, fieldPname(myTable,Day), myTable.Day));
    

    I often use this technique with setPrefix instead:

    setPrefix(strFmt('%1: %2, %3: %4', fieldPname(myTable,AliasUser), myTable.AliasUser, fieldPname(myTable,Day), myTable.Day));
    info("More specific message here");
    

    If only one field use the PrefixField macro:

    setPrefix(#PrefixField(myTable,AliasUser));
    info("More specific message here");
    

    or the PrefixFieldValue sister:

    setPrefix(#PrefixField(myTable, AliasUser, myTable.AliasUser+':'));
    info("More specific message here");