Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Loop through grid fields in Ax 2012 in RUNTIME

Posted on by 15

Hello,

I need logic to loop through columns(fields) in grid in runtime.

Something similar to this AX 2012: Loop through all the fields of a table in X++ - Dynamics 365 Finance Community  but in runtime.

For example if grid data source has 5 columns and 3 are removed in UI, i want to loop just through these 2 that are left in the grid. So my question is how to get grid fields in runtime( not from datasource table) ?

Thank you.

  • Loop through grid fields in Ax 2012 in RUNTIME
    I was also looking for this information. Luckily I saw your post. Thanks a lot. slope 3
  • Loop through grid fields in Ax 2012 in RUNTIME
    I was also looking for this information.
  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    isVisible Example

    pastedimage1661804439400v1.png

    pastedimage1661804526044v2.png

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    You can use isVisible

    Set all fields's autoDecleration to Yes and check with control.isVisible

    As a alternative I wrote a code with treeNode but it seems treeNode can't get usage Data from user. I didn't want spent to much time, probably I didn't catch some point. Here the code, maybe it can be helpfull

    static void dmr_ES_GetFormFieldsInfoWithTreeNode(Args _args)
    {
        TreeNode        treeNode = TreeNode::findNode(@'\Forms\DmrESTestFormVisible\Designs\Design\[Grid:Grid]');
        treeNode        treeNodeChild;
        TreeNodeType    treeNodeType;// = treeNode.treeNodeType();
        FormControl     FormControl;
        
        FormTreeControl FormTreeControl;
        
        void nodeInfo(treeNode _treeNode)
        {
            if(treeNodeChild.treeNodeName() != "Methods")
            {
                treeNodeType = _treeNode.treeNodeType();
               
                //info(strFmt("Id: %1", treeNodeType.id()));
                info(strFmt("Name: %1", _treeNode.treeNodeName()));
                info(strFmt("Name: %1", _treeNode.AOTname()));
                info(strFmt("AllProperties: %1", _treeNode.AOTgetProperties()));
                
                info(strFmt("Visible: %1", _treeNode.AOTgetProperty("Visible")));
                info(strFmt("isVisible: %1", _treeNode.AOTgetProperty("Visible")));
            }    
        }
        if(treeNode)
        {            
            if(treeNode.AOTchildNodeCount())
            {
                treeNodeChild = treeNode.AOTfirstChild();
                
                nodeInfo(treeNodeChild);
                while(treeNodeChild.AOTnextSibling())
                {             
                    treeNodeChild = treeNodeChild.AOTnextSibling();   
                    nodeInfo(treeNodeChild);
                }
            }
        }
    }

  • Viktors Profile Picture
    Viktors 15 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    Yes, I know and I thought that SysExcel classes do it, but I investigated them and they don't do anything related to that what I need.

    So if you have any documentation or reference about Export to Excel function please share with me, thank you.

    kind regards

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,269 Super User 2024 Season 2 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    Moved to the Dynamics AX forum.

    Hi Viktors,

    The Export to Excel from the Grid is actually doing the same job (exporting the columns visible on the grid). You can review how Microsoft did implement it for this feature.

  • Viktors Profile Picture
    Viktors 15 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    Hi,

    Yes, I am asking about Dynamics AX 2012 grid, i want to loop through all fields in the grid.

    So if I loop through data source of the grid I can achieve it, but if user personalize the grid(add or remove columns on UI) I want to loop through these columns, so that's why I need to catch grid in runtime.

    kind regards

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,269 Super User 2024 Season 2 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    Hi Viktors,

    Is your question related to Dynamics AX 2012?

  • Viktors Profile Picture
    Viktors 15 on at
    RE: Loop through grid fields in Ax 2012 in RUNTIME

    This looks totally different from that what i am looking for.

    I need to get grid in the runtime to do additional operations in backend.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans