web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    You can use TreeNode::findNode

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

  • Community Member Profile Picture
    on at

    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

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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

    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
    237,965 Most Valuable Professional on at

    Which of the things mentioned above do you mean?

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    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);
        }
    }

  • ergun sahin Profile Picture
    8,826 Moderator on at

    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,826 Moderator on at

    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);
        }
    }

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    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

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans