web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / how to get ParentNode ...
Finance forum

how to get ParentNode form child node path?

(0) ShareShare
ReportReport
Posted on by 932

Hi,

I want to get the parent Node path  from child node path 

example:

child node=\Menus\AccountsReceivable\Customers                                 parent Node=\Menus\AccountsReceivable

childe node=\Menus\AccountsReceivable\Customers\All customers        parent Node=\Menus\AccountsReceivable\Customers

there is any method that cand do this?

  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Basma,

    Have you got the path of the child node?

    You can use strFind() to search.

    int strFind(str _text, str _characters, int _position, int _number);


    To search from the beginning of the string to the end, use 1 as the value of the _position parameter. If the value of the _number parameter is negative, the system searches the number of characters backward from the specified position. The search isn't case-sensitive.

    In this way, you can get the last position of ”\“. Then you can substring the child nodes.

    More string runtime functions, refer: https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-ref/xpp-string-run-time-functions#strfind

  • Suggested answer
    Martin Dráb Profile Picture
    240,742 Most Valuable Professional on at

    Can you share some context, please? Where do you get these paths?

    There is a good chance that you can use the object model instead of mere strings representing paths.

    If you want use the paths, you can use strSplit() to split a path to its components.

  • BASMA Profile Picture
    932 on at

    Hi @Martin ,

    the purpose of this task is to get the reciId of parentNode

    so, I want first to get the path of parent Node from the path of child node

  • Martin Dráb Profile Picture
    240,742 Most Valuable Professional on at

    RecId of which table? Source code and metadata aren't stored in database and therefore there is no such thing as a record ID of a menu.

    If you're talking about a custom table, please realize that we know nothing about it. You'll have to explain your data model before we can tell you how to use it or propose a better design.

  • BASMA Profile Picture
    932 on at

    It's a custom table:

    1185.parentNode.png

    I insert data through runnable class .

    now I want to update this table to insert parenNode.

    example:

    \Menus\AccountsReceivable\Customers\All customers       parenNode=recId of  "\Menus\AccountsReceivable\Customers"

    I use this code to insert data

    TreeNode menuItemNode = TreeNode::findNode(@"\Menus\AccountsReceivable");
                    SysDictMenu      _menu;
                    str              formName;
                    AcxNodeTable1   _acxNodeTable;
                    AcxNodeReferenceTable   _acxNodeReferenceTable;
                    _menu = SysDictMenu::newTreeNode(menuItemNode);
                  //  delete_from _acxNodeTable;
                  //  delete_from  _acxNodeReferenceTable;
                    
                    boolean iterateMenus(SysDictMenu _cmenu)
                    {
                        SysMenuEnumerator menuEnum = _cmenu.getEnumerator();
                        SysDictMenu subMenu;
                        SysDictMenu parentSubMenu;
                        boolean found;
    
                        while (menuEnum.moveNext())
                        {
                            subMenu = menuEnum.current();
         
                        ttsbegin;
                    _acxNodeTable.clear();
                    _acxNodeTable.Node=subMenu.object().treeNodePath();
                    _acxNodeTable.NodeDescription=subMenu.label();
                    _acxNodeTable.insert();
                    ttscommit;
                            if (subMenu.isMenu() || subMenu.isMenuReference())
                            {
                                //info ("Menu "+subMenu.object().treeNodePath());
                                setPrefix(subMenu.label());
                                
                                found = iterateMenus(subMenu);
                                if (found)
                                {
                                    return found;
                                }
                            }
                            else if ((subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Display && subMenu.isVisible())
                                   || (subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Action && subMenu.isVisible())
                                   || (subMenu.isMenuItem()&& subMenu.menuItem().type() == MenuItemType::Output && subMenu.isVisible()))
                            {
                           
                                 info(subMenu.label());
                              //info("Menu Item "+ subMenu.object().treeNodePath());
                                /*FormName=subMenu.getMenuItemFormName();
                                info("Forme "+subMenu.getMenuItemFormName());*/
    
                            }
                           
                        }
    
  • Martin Dráb Profile Picture
    240,742 Most Valuable Professional on at

    Why don't you do it when inserting data to the table? You know the parent at that point, therefore you can insert the parent and then use its ID for all children.

    If you ignore the information at that time, you'll have to go through all records again, which is expensive.

  • BASMA Profile Picture
    932 on at

    I am looking for a solution, how can I insert the RecId of parent Node

  • Martin Dráb Profile Picture
    240,742 Most Valuable Professional on at

    _acxNodeTable.ParentNode = parent.RecId

    I guess you meant something else, but I don't know what. I can't do anything more for you unless you explain your problem properly.

  • BASMA Profile Picture
    932 on at

    I dont understand your suggestion : how can I get the parent node recId  from the child

    when I loop the childs how can I get the parent Node

    there is function that returns  the path of parentNode : this is what I want

  • Verified answer
    Martin Dráb Profile Picture
    240,742 Most Valuable Professional on at

    Oh, so you didn't even previous reply either...

    Your proposed solution is inserting records for all elements (ignoring the parent at that point) and then going through everything again and trying to find the parent. It means that you ignore the information when you have it and you're trying to expensively reconstruct it later.

    My suggestion is changing your design. You'll start by inserting the parent node, which will give you its record ID. Then you'll iterate the child nodes and when you're inserting records for them, you'll simply populate ParentNode field with the ID of the parent.

    Your design is possible too, but it would mean more work to get much worse performance, therefore it doesn't look reasonable to me.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans