While working on the documentation phase for an AX 2012 project I needed a way to speed up a few things. One of the requirements for the documentation was to add a description of all enumerations that has been used by this project. The result was a simple but powerful script which recursively traverse all nodes of a project to find all enumerations. For each enumeration that is found the actual values are printed.
Of course it is a very specific script for a certain purpose but you can of course change it to gather other kinds of information.
static void JM_ExportProjectEnumValues(Args _args)
{
ProjectListNode sharedProjList = infolog.projectRootNode().AOTfindChild("Shared");
ProjName projName;
ProjectNode projNode;
ProjectNode projNodeLoad;
#TreeNodeSysNodeType
// warning: recursive function
void traverseProjectNodes(ProjectNode _rootNode)
{
TreeNode childNode;
TreeNodeIterator rootNodeIterator;
TreeNodeType treeNodeType;
DictEnum dictEnum;
int enumValueIdx;
;
if (_rootNode)
{
rootNodeIterator = _rootNode.AOTiterator();
childNode = rootNodeIterator.next();
while (childNode)
{
treeNodeType = childNode.treeNodeType();
//info(strfmt("%1: %2 - %3", treeNodeType.id(), rootNode.AOTname(), childNode.AOTname()));
// found group: jump in
if (treeNodeType.id() == #NT_PROJECT_GROUP)
traverseProjectNodes(childNode);
// found base enum
if (treeNodeType.id() == #NT_DBENUMTYPE)
{
dictEnum = new DictEnum(enumName2Id(childNode.AOTname()));
if(dictEnum)
{
info(strFmt("ID:%1 NAME:%2", dictEnum.id(), dictEnum.name()));
for(enumValueIdx = 0; enumValueIdx < dictEnum.values(); enumValueIdx++)
{
info(strFmt("%1 = %2", dictEnum.index2Value(enumValueIdx), dictEnum.index2Label(enumValueIdx)));
}
}
}
childNode = rootNodeIterator.next();
}
}
};
// traverse all enums of a given project
projName = ""';
projNode = sharedProjList.AOTfindChild(projName);
projNodeLoad = projNode.loadForInspection();
traverseProjectNodes(projNodeLoad);
projNodeLoad.treeNodeRelease();
}