Wednesday, 6 April 2016

How to count no.of Methods and display the method names in a class using X++ Code

static void Raj_CountMethodsinClass(Args _args)
{

    SysDictClass sysDictClass  = new SysDictClass(481);// Provide the ClassID
    TreeNode    treeNode = TreeNode::findNode(sysDictClass.path());
    TreeNode    childNode;
    Counter     counter = 1;

    if (treeNode)
    {
        info(strfmt('Number of methods in the class: %1',treeNode.aotchildnodecount()));
        childnode = treenode.aotfirstchild();
        while(counter <= treeNode.aotchildnodecount())
        {
            info(childNode.treeNodeName()); //Print the methods name
            //info(childNode.AOTgetSource()); Uncomment this to print the coding of the method
            childNode = childNode.aotnextsibling();
            counter++;
        }
    }
}

No comments:

Post a Comment