Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to find any node in AOT using name

(0) ShareShare
ReportReport
Posted on by

Hello Every One,

Is it possible to find a node under AOT ? (eg: Queries/Data sources/datasource1/datasource2).

As mentioned in the above example Under queries I have Data sources again data sources inside data sources and so on. Now I would like to find data source node using it's name . Either it may be direct node or child or grand child ...

Thanks,
Phani

  • Suggested answer
    Hossein.K Profile Picture
    6,646 on at
    RE: How to find any node in AOT using name

    Hi

    If you could query the Dynamics AX Model Database to find a string across all objects? Well, using the simple SQL Query below, you can. Here’s how to search X code using Dynamics AX model database:

    SELECT RootHandle.Name    RootElementName,
    
        ElementHandle.Name    ElementName,
    
        ElementTypes.ElementTypeName  Type,
    
        CAST(Sources.SourceText AS nvarchar(MAX)) SourceText
    
    FROM Sources Sources
    
        JOIN ModelElement ElementHandle
    
      ON Sources.SourceHandle     = ElementHandle.ElementHandle
    
        JOIN ModelElement RootHandle
    
      ON RootHandle.ElementHandle = ElementHandle.RootHandle
    
        JOIN ElementTypes ElementTypes
    
      ON ElementTypes.ElementType = ElementHandle.ElementType
    
    WHERE CAST(Sources.SourceText AS nvarchar(MAX)) LIKE '%h.karimi%'

    pastedimage1620719259438v1.png

     
  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to find any node in AOT using name

    Thinking about it, there is no need to hesitate the loop as long as we don't print to the screen.
    I've written something more general below. The code is returning all the nodes. I just printed out dataSource and relations but you can see the whole tree if you open the closed info

    static void getNodeNames(Args _args)
    {
        #AOT
        TreeNode    rootObjTreeNode;
        void getNode(TreeNode    _objTreeNode)
        {
            TreeNode    objTreeNode = _objTreeNode;
            TreeNode    objTreeNodeTmp;
            objTreeNode = objTreeNode.AOTfirstChild();
            while (objTreeNode)
            {
                if(objTreeNode.AOTparent() && objTreeNode.AOTparent().treeNodeName() == "Data Sources")
                {
                    info("------DATASOURCENAME------"   objTreeNode.treeNodeName());
                    info(objTreeNode.treeNodePath());
                }
                if(objTreeNode.AOTparent() && objTreeNode.AOTparent().treeNodeName() == "Relations")
                {
                    info("------Relations------"   objTreeNode.treeNodeName());
                }
                //all object info
                //info(objTreeNode.treeNodeName());
                
                if(objTreeNode.AOTfirstChild())//objTreeNode.treeNodeName() == "Data Sources")
                {              
                    getNode(objTreeNode);
                }
                
                objTreeNode = objTreeNode.AOTnextSibling();
                
            }
        }
        ;
        
        //rootObjTreeNode = TreeNode::findNode(#QueriesPath   "\\"   queryStr(custAutoSettlement));
        //rootObjTreeNode = TreeNode::findNode(#FormsPath   "\\"   formStr(CustBillingCode));
        rootObjTreeNode = TreeNode::findNode(#ViewsPath   "\\VendorView" );
        if(rootObjTreeNode)
        {
            getNode(rootObjTreeNode);
        }
    }

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to find any node in AOT using name

    For Form DataSouce

    static void getFormDataSourceNames(Args _args)
    {
        #AOT
        TreeNode    rootObjTreeNode;
        void getNode(TreeNode    _objTreeNode)
        {
            TreeNode    objTreeNode = _objTreeNode;
            TreeNode    objTreeNodeTmp;
            objTreeNode = objTreeNode.AOTfirstChild();
            while (objTreeNode)
            {
                if(objTreeNode.treeNodeName() == "Data Sources")
                {              
                    getNode(objTreeNode);
                }
                if(objTreeNode.AOTparent() && objTreeNode.AOTparent().treeNodeName() == "Data Sources")
                {
                    info(objTreeNode.treeNodeName());
                }
                objTreeNode = objTreeNode.AOTnextSibling();
            }
        }
        ;
    
        //rootObjTreeNode = TreeNode::findNode(#QueriesPath   "\\"   queryStr(custAutoSettlement));
        rootObjTreeNode = TreeNode::findNode(#FormsPath   "\\"   formStr(CustBillingCode));
        if(rootObjTreeNode)
        {
            getNode(rootObjTreeNode);
        }
    }

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to find any node in AOT using name

    If you want to see all the objects, it is possible to write a common structure that goes around the tree, but the code will visit the nodes that you are not interested in.
    If you want something more targeted, you need to play with codes. For example, below I wrote a code that browses the datasources under Query. It is possible to write similar things.

    static void getQueryDataSourceNames(Args _args)
    {
        #AOT
        TreeNode    rootObjTreeNode;
        void getNode(TreeNode    _objTreeNode)
        {
            TreeNode    objTreeNode = _objTreeNode;
              
            objTreeNode = objTreeNode.AOTfirstChild();
            while (objTreeNode)
            {
                if(objTreeNode.treeNodeName() == "Data Sources")
                {
                    objTreeNode = objTreeNode.AOTfirstChild();
                    if(objTreeNode)
                    {
                        info(objTreeNode.treeNodeName());
                        getNode(objTreeNode);                           
                    }
                    else
                        return;
                }          
                objTreeNode = objTreeNode.AOTnextSibling();
            }   
        }
        ;
    
        rootObjTreeNode = TreeNode::findNode(#QueriesPath   "\\"   queryStr(custAutoSettlement));
       
        if(rootObjTreeNode)
        {
            getNode(rootObjTreeNode);
        }
    }

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to find any node in AOT using name

    Which of the things mentioned above do you mean?

  • Community Member Profile Picture
    on at
    RE: How to find any node in AOT using name

    Hi Martin,

    Thanks for you reply,

    Is the above applicable also for other AOT nodes like Queries or is it bit different?

    Thanks,

    Phani

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to find any node in AOT using name

    You have two main options. Either you'll use generic reflections APIs, such as TreeNode (TreeNodeIterator etc.) or SysModel* tables.

    Or, in this particular case, you can use methods of FormRun and related classes. For example:

    FormDataSource formDataSource;
    int i;
    
    for (i = 1; i <= formRun.dataSourceCount(); i  )
    {
    
    	formDataSource = _formRun.dataSource(i);
    	if (formDataSource.name() == xyz)
    	{
    		...
    	}
    }

  • Community Member Profile Picture
    on at
    RE: How to find any node in AOT using name

    Hi Ergün Şahin,

    My code should be generic like under Address form there is a data source and again inside one more data source . so just passing a data source name  

    is it possible to find the data source node.it can be present in parent level, child or grand child level. I don't want to point directly as you mentioned above. if it is possible to search be data source name that would help.

    Thanks,

    Phani

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to find any node in AOT using name

    You can use TreeNode::findNode

    TreeNode::findNode("\\Forms\\Address\\Data Sources\\Address\\Methods\\delete");

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,267 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans