generating method (with specific code) from X++ code

So the issue was that I was supposed to create bunch of methods ( like parm) , when I knew the table fields, and where they had really similar code.

Instead doing that manually I have created a following job. Hope it helps 🙂

static void aka_createDetermineMethods(Args _args)
     TreeNode tnclass, tntable,tnfield;
     MemberFunction tnMethod;
     str name;
     str code = "protected %1 %2()\n"+
                "//overwritten in sub classes\n"+
                " return '%3';\n"+

     tnClass = TreeNode::findNode(@"\Classes\[class to add methods]");
     tntable = TreeNode::findNode(@"\Data Dictionary\Tables\CustTable\Fields");
     tnfield = tntable.AOTfirstChild();

    while (tnfield)
         name = "parm"+tnfield.treeNodeName();
         tnMethod = tnClass.AOTfindChild(name);
        if (!tnMethod)
            tnMethod = tnClass.AOTadd(name);
        tnMethod.AOTsetSource(strFmt(code, tnfield.AOTgetProperty("ExtendedDataType"), name,name));
        tnfield = tnfield.AOTnextSibling();

Debugging on server is impossible, but yet is required

If you have faced the similar situation using Microsoft Dynamics AX, do not worry as there are few solutions that may help you. Sometimes there are even less time consuming than the debugging in server itself.

One of the most favourite ones is to enter all data in the file, and than be able to trace necessary data. you Can find example below

 AsciiIo file;
 FileName fileName;
 FileIoPermission perm;
 container conTextLine;

 fileName = @"\\c:\temp\sometext.txt";

perm = new FileIoPermission(fileName, 'W');


file = new AsciiIo(fileName, 'W');

//super smart code that needs debuggin
 file.writeRaw("Super  secret value to export");
//some other code

 file = null;

Change amount of visible elements on the form depending on selected record.

I was creating form and regarding on the value of the record, I had to add or remove specific form elements ( fields and etc. )

The most convenient place to do that is on a data source, in method Active. It is possible that you have to try few data sources and decide which one suits you more.

Although this doesn’t work during initialization of the form. When you open the form it gathers 0 instead of actual record value.

generating CSV record with labels out of table fields

So pretty much this is the way to generate a line of csv file, getting value of the query table daa soucre field label values.

QueryRun qR;
Query _query;
Common record;

DictTable dictTable;
FieldId fieldId;
DictField dictField;

str output =””;
int x,y;

_query = new Query(“<nameOfTheQuery>”);
qR = new QueryRun(_query);
for(x = 1; x <= _query.dataSourceCount(); x++)

dictTable = new DictTable(_query.dataSourceNo(x).table());
for(y = 1; y <= _query.dataSourceNo(x).fields().fieldCount(); y++)
fieldId = _query.dataSourceNo(x).fields().field(y);
dictField = new DictField(, fieldId);

if(dictField.arraySize() > 1)

output += strFmt(“%1%2”, dictField.label(), “|”);

info( output);

Update help property if label exists

If you really need to copy existing label property to another property for example help text (that isn’t really best practice , I know 😦  ) this code can be used.

static void KindaBestPractiseThingy(Args _args)
TreeNode fields = TreeNode::findNode(@”\Data Dictionary\Tables\<TableName>\Fields”);
TreeNodeIterator fieldsIterator;
TreeNode field;
str label;

fieldsIterator = fields.AOTiterator();
field =;
Label = field.AOTgetProperty(#PropertyLabel);
Field.AOTsetProperty(#PropertyHelpText, Label);
field =;

when writing lookups

When you create lookups and don’t know all details by heart, this example proves to be really useful. It was found somewhere in the Internet, so if you know where it is taken from please comment and I will link to the author blog post.


Query query = new Query();
 QueryBuildDataSource qbds;
 QueryBuildDataSource qbdsJoin;
 SysTableLookup sysTableLookup = sysTableLookup::newParameters( tableNum(VendTable), this);
 qbds= query.addDataSource( tableNum(VendTable));
 qbdsJoin= qbds.addDataSource( tableNum(DirPartyTable));
 qbdsJoin.relations( false);
 qbdsJoin.addLink( fieldNum(VendTable, Party), fieldNum(DirPartyTable, RecId));
 sysTableLookup.addLookupfield( fieldNum(VendTable, AccountNum), true);
 sysTableLookup.addLookupfield( fieldNum(VendTable, VendGroup), true);
 sysTableLookup.addLookupfield( fieldNum(VendTable, Party));