Use X++ to Loop through the AOT


Recently, I had a need to loop through the Forms node in the AOT and find any form that had a particular property value.  I’ve seen a lot of examples that show you how to locate nodes in the AOT by name, but not by a property value. So I thought I would share the code that I wrote for the task.

For a little background, when you press F1 on a form in AX, it brings up a help topic for that form. Each form is hooked up to help via the HTMLHelpTopic property (and the HTMLHelpFile property if you want to get precise). To find this property you need to open the form in the AOT and then navigate to the Design node.

 

Here’s the code that loops through the forms.

static void FindFormInAOT(Args _args)

{

    #AOT

    Treenode formNode;

    Treenode form;

    Form actualForm;

    str HTMLHelpProperty;

    str formName;

    int i;

    int nodeCount;

    ;

    formNode = treenode::findNode(#FormsPath);

    // Count of all the forms.

    nodeCount = formNode.AOTchildNodeCount();

    form = formNode.AOTfirstChild();

 

    for (i=1; i<=nodeCount; ++i)

    {

        formName = form.AOTgetProperty(“Name”);

 

        actualForm = formNode.AOTfindChild(formName);

        // Get the HTMLHelpTopic property.

        HTMLHelpProperty = actualForm.design(0).hTMLHelpTopic();

        if (strScan(HTMLHelpProperty, “386c78e8-16c3-404f-aad2-d50248c26905”, 1, strLen(HTMLHelpProperty))>1)

        {

            info(“Form name is: ” + formName);

            break;

        }

        form = form.AOTnextSibling();

    }

}

If successful, the code displays and Infolog window with the matching form name.

 

Comments (3)

  1. Manoj Louis Padikkala says:

    This is extremly fantastic and useful article. Thanks very much and appreciate your help!

  2. RLP says:

    Is this something you have to do programmatically, or are you just trying to find forms that have a specific property?   Because you can use AX's Find in the AOT to find forms with a given property.

    To find property names with a specific value

    a. In the AOT, right-click the node or application object to search

    b. Click Find. The Find dialog box opens.

    c. On the Name & Location tab, set the Search field to All nodes

    d. In the Containing text field, enter a property name and a value in the following format:

    PropertyName: *#PropertyValue     [Note: The symbols are as follow: colon space asterisk hash]

    e. Click Find now

    All property names that contain the specified value are shown in the output window for the selected node in the AOT.

    For example, in the AOT, if you search the Workflow node, and enter Module: *#Vendor in the Containing text field, only application objects that have a property named Module where the value is set to Vendor are displayed.

    (source: msdn.microsoft.com/…/aa661186 )

  3. Cris says:

    @ RLP

    This code can be altered a bit to find MODIFIED objects in an specific layer using SysTreeNode::existsInLayer(treeNode, PUTYOURLAYERHERE), not only the forms, but the tables using #TablesPath or Classes using #ClassesPath.

    It is a great article, very useful.

    Thanks