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, ...
Answered

Get all form Parts (FormContainerControl) form controls in D365FO

(0) ShareShare
ReportReport
Posted on by 336

Hello, i have a quick technical question, 

I want just to loop all Form Part exist in a given form, 

here is my code to retrieve all Form Parts from DirPartyTable form 

pastedimage1575299402181v1.png

But i can't get the result

public class TestFormParts
{
    public void findFormParts(FormBuildControl _buildControl)
    {
        Set                 buttonsSet = new Set(Types::Class);


        FormBuildControl    buildControl;
        int                 i;
        ;

        if (_buildControl.controlCount() > 0)
        {
            for (i = 1; i <= _buildControl.controlCount(); i  )
            {
                buildControl = _buildControl.controlNum(i);
                Info(strFmt("%1", _buildControl.name()));
                this.findFormParts(buildControl);
                
            }
        }
        else
        {
            if (classidget(_buildControl) == classnum(FormContainerControl))
            {
                buttonsSet.add(_buildControl);
            }
        }
    }

    public static void main(Args _args)
    {
        TestFormParts tes = new testFormParts();
        Form                myForm;
        FormBuildDesign     design;
        FormBuildControl    control;
        FormRun             formRun;
        int                 cnt = 0;

        _args = new Args();
        _args.name(formStr(DirPartyTable));
        formRun = classfactory.formRunClass(_args);
        myForm = formRun.form();
        design = myForm.design();

        for (cnt = 1; cnt <= design.controlCount(); cnt  )
        {
            control = design.controlNum(cnt);
            tes.findFormParts(control);
        }
    }

}

Thanks

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi Adax,

    Did you try New metadata API?

    Please refer this blog: community.dynamics.com/.../new-metadata-api

    Previously there were similar threads that traversed all controls of the form:

    community.dynamics.com/.../how-to-get-all-form-buttons

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Try the following; I used it in AX 2012.

    PartList partList = new PartList(formRun);
    
    for(int i = 1; i <= partList.partCount(); i  )
    {
        FormRun part = partList.getPartById(i);
    }

  • AdnDalhi Profile Picture
    336 on at

    Hi Martin,

    I've tried this, my Following code now is:

    PartList always null

    public class GetFormParts
    {
        public static void main(Args _args)
        {
            Form                myForm;
            FormBuildDesign     design;
            FormBuildControl    control;
            FormRun             formRun;
    
            _args = new Args();
            _args.name(formStr(DirPartyTable));
            formRun = classfactory.formRunClass(_args);
    
            PartList partList = new PartList(formRun);
    
            for(int i = 1; i <= partList.partCount(); i  )
            {
                FormRun part = partList.getPartById(i);
            }
        }
    }

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

    If I was you, I would try it on a running form. I assume you would learn that it works there and the bug in your code is caused by something else than the code I gave you. I see you haven't initialized the form (formRun.init()), which looks like the key problem to me.

  • AdnDalhi Profile Picture
    336 on at

    Hi Blue Wang.

    Traversing all form controls, doesn't access to FormParts

    In DirPartyTable standard form, exist 2 form parts, while looping through all controls, the process stop on TabPage parents of these 2 form parts, stop on AddressTabePage, ContactInfoTabPage, and can't access to AddressGridFormPart & ContactInfoFormPart

    pastedimage1575368955987v1.png

  • AdnDalhi Profile Picture
    336 on at

    AddressGridFormPart & ContactInfoFormPart controls in DirPartyTable form, have "FormContainerControl" as a type

    pastedimage1575371514743v1.png

    AddressGridFormPart:

    pastedimage1575371578158v2.png

    ContactInfoFormPart:

    pastedimage1575371595735v3.png

    I'm wondering if looping partList can help to get these 2 controls.

    Here is the result of my code, i got the associated FactBox of DirPartyTable form and not AddressGridFormPart & ContactInfoFormPart controls (type FormContainerControl.) the goal

    public class GetFormContainerControls
    {
        public static void main(Args _args)
        {
            FormRun             formRun;
    
            _args = new Args();
            _args.name(formStr(DirPartyTable));
            formRun = classfactory.formRunClass(_args);
            formRun.init();
    
            PartList partList = new PartList(formRun);       
    
            for(int i = 1; i <= partList.partCount(); i  )
            {
                FormControl fcontrol = partList.getPartControlById(i);
                
                if(fcontrol)
                {
                    Info(strFmt("the part control name %1", fcontrol.name()));
                }
                
                //FormRun part = partList.getPartById(i);
                //if(part.name()) NULL
                //{
                //    Info(strFmt("the part name %1", part.name()));
                //}
            }
        }
    }

    pastedimage1575371861149v4.png

    pastedimage1575371990568v5.png

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

    No, it won't, because it's a different thing. To work form controls, you can use the approach mentioned in your question and the first reply in this thread.

    It looks like that you original question is now answered. If it's the case, please mark the verified answer. Feel free to create new threads if you have other topics to discuss.

  • AdnDalhi Profile Picture
    336 on at

    Yes I'm trying to solve it, by using first approach of my first post, by looping all controls and get sub controls when CountrolCount()>0.

    The goal is get AddressGridFormPart  and ContactInfoFormPart controls 

    pastedimage1575382480788v2.png

    AddressGridFormPart and ContactInfoFormPart (FormContainerControl) exist in TabPages (AddressTabPage & ContactInfoTabPage)

    My code access to AddressTabPage control, but can't loop through to get "AddressGridFormPart

    The same for ContactInfoTabPage with "ContactInfoFormPart".

    Here is my code 

    using Microsoft.Dynamics.AX.Metadata.MetaModel;
    
    public class GetFormContainerControls
    {
        public static void main(Args _args)
        {
            GetFormContainerControls tes = new GetFormContainerControls();
            Form                myForm;
            FormBuildDesign     design;
            FormBuildControl    control;
            FormRun             formRun;
            int                 cnt = 0;
    
            _args = new Args();
            _args.name(formStr(DirPartyTable));
            formRun = classfactory.formRunClass(_args);
            myForm = formRun.form();
            design = myForm.design();
    
            for (cnt = 1; cnt <= design.controlCount(); cnt  )
            {
                control = design.controlNum(cnt);
                tes.findformContainerCtrls(control);
            }
        }
    
        public void findformContainerCtrls(FormBuildControl _buildControl)
        {
            FormBuildControl    buildControl;
            int i;
            ;
    
            if (_buildControl.controlCount() > 0)
            {
                for (i = 1; i <= _buildControl.controlCount(); i  )
                {
                    buildControl = _buildControl.controlNum(i);
                    this.findformContainerCtrls(buildControl);
                }
            }
            else
            {
                if (((classidget(_buildControl)) == classNum(FormBuildTabPageControl))) //Here i want access to the TabPage (AddressTabPage & ContactInfoTabPage)
                {
                    if(_buildControl.isContainer()) //Here i check if the this tabPage is container
                    {
                        for (i = 1; i <= _buildControl.controlCount(); i  ) //Here always is controlCount = 0, no loop
                        {
                            buildControl = _buildControl.controlNum(i);
                            Info(strFmt(" Form container Control name %1", _buildControl.name())); //Here i wanna show the FormContainerCntrolName (AddressGridFormPart & ContactInfoFormPart)
                            this.findformContainerCtrls(buildControl);
                        }
                    }
                }
            }
        }
    }

  • AdnDalhi Profile Picture
    336 on at

    Hi Blue Wang,

    The prvious post, Don't access to all Controls, here the need is different,

    Is getting FomContainerControl type from TabPage,  (Example from DirPartyTable, see previous screeshots)

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Here is how you can do it with the new metadata API mentioned at the beginning:

    using Microsoft.Dynamics.AX.Metadata.MetaModel;
    
    class MetadataDemo
    {
        public static void main(Args _args)
        {
            AxForm form = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetForm(formStr(DirPartyTable ));
            new MetadataDemo().showCollectionControlNames(form.Design);
        }
    
        private void showCollectionControlNames(IFormControlCollection _control)
        {
            var controlEnumerator = _control.Controls.GetEnumerator();
     
            while (controlEnumerator.MoveNext())
            {
                AxFormControl control = controlEnumerator.Current;
    
                if (control is IFormControlCollection)
                {
                    info(control.Name);
                    this.showCollectionControlNames(control as IFormControlCollection); // Recursion
                }
            }
        }
    }

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 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans