Reputation: 71
Is there any way for me to get, by code, a list of all the methods in a given form in Dynamics AX 2012?
I am working in developing a small tool that will insert some comments in all of the methods of custom objects through using the Editor class. However, to do so, I need the full path of each method (ex: \Classes\MyClass\CustomMethod), but I simply can't find any way to get this working for Forms.
Thanks in advance!
Upvotes: 3
Views: 2000
Reputation: 71
Thanks for sending me suggestions. I actually just finished writing some code to get me the information. Here is the code, for anyone who may be interested:
//I used the BatchJobHistory form as a test, since I called this static method from a job
public static void findAllChildNodes(str _nodeName = "\\Forms\\BatchJobHistory", boolean _isMethod = NoYes::No)
{
TreeNode treeNode;
TreeNodeIterator treeNodeIterator;
treeNode methodsNode;
str treePath;
boolean containsMethod;
treeNode = TreeNode::findNode(_nodeName);
treeNodeIterator = treeNode.AOTiterator();
methodsNode = treeNodeIterator.next();
while(methodsNode)
{
treePath = methodsNode.treeNodePath();
containsMethod = strScan(treePath, 'Methods', 1, strLen(treePath));
if (methodsNode.AOTchildNodeCount())
{
//TestClass is the class containing this method
TestClass::findAllChildNodes(treePath, containsMethod);
}
else if (_isMethod)
{
info(strFmt("%1", treePath));
}
methodsNode = treeNodeIterator.next();
}
}
Upvotes: 3
Reputation: 11564
Here's a question that should point you in the right direction, albeit you'll need to expand on it.
AX2009 Loop through all the controls in the form on init
The general theme you'll probably need to work with is recursion
(https://en.wikipedia.org/wiki/Recursion_(computer_science)), reflection
, and use of the TreeNode
and derivatives of the class to do Tree Node Traversal
(https://en.wikipedia.org/wiki/Tree_traversal)
I'm also imagining you'll need to use some of the layer-aware methods if you're trying to decorate methods with comments. It sounds fun what you're trying to do, but a little bit of a pain. I'd expect it to take at least half a day to do properly.
Upvotes: 1