Ax 2012

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"+
                "{\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);
            info(tnfield.treeNodeName());
        }
        tnMethod.AOTsetSource(strFmt(code, tnfield.AOTgetProperty("ExtendedDataType"), name,name));
        tnfield = tnfield.AOTnextSibling();
   }
}
Ax 2012

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');

perm.assert();

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

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

file.finalize();
 file = null;