Monday, May 05, 2014

Q&A session: Working with MorphX project nodes from code

I had some spare time today, so started answering some of the comments I had through the blog and through e-mail. I decided I'll just open up a new section on my blog, called Questions and Answers, in which I will slowly answer the questions from my backlog:

Question (related to post about the DEV_CreateNewProject tool for AX):
So could create ConfigKeys Macro and I wanted, and could throw them into the project that was created, but I can not throw them within their respective nodes, so they are loose in the project, you can help me put them within your nodes?

To summarize, Gustavo wanted to create some AOT elements from code (specifically, configuration keys and macros), and add them to a new project into respective groups, similar to how it is done in DEV_CreateNewProject tool.

I wrote a small job that does that, and can be downloaded from my OneDrive. The code is also pasted and explained below:

static void Tutorial_CreateProjWithGroupAndElement(Args _args)
    ProjectListNode     treeNodeProject;
    ProjectNode         upgradeNode;
    ProjectGroupNode    child;
    MacroBuild          macro;

    str projName = @"Project01";
    str groupName = @"macroGrp";
    str macroName = @"macro01";

    treeNodeProject = SysTreeNode::getPrivateProject();
    upgradeNode = treeNodeProject.AOTfindChild(projName);
    upgradeNode = upgradeNode.getRunNode();

    child = upgradeNode.AOTfindChild(groupName);

    macro = new MacroBuild(macroName, true);

    child.addUtilNode(UtilElementType::Macro, macroName);


  • SysTreeNode class is used to retrieve the object for the root of the Private projects node. This class contains a number of interesting methods for anyone who wants to navigate and manage AOT nodes
  • Standard AOTadd and AOTfindChild methods are used for first creating and then loading the contents of the node into a TreeNode object for processing.
  • getRunNode is used on the project node so that it is not just loaded for processing, but also opened in a new window to show the result to us after executing the job
  • MacroBuild class is used to creating new Macros, and is similar to a ClassBuild that I described previously
  • addUtilNode is the key method Gustavo was missing, and allows to add the macro created to the project group node. 
  • AOTsave() is used to persist all the changes done to the project as well as the new macro.

You can see the results immediately after executing the job.