Skip to main content

Notifications

Announcements

No record found.

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

How to create a dynamic fields in form?

(0) ShareShare
ReportReport
Posted on by 1,550

Hi,

I want to create a control in form by code (not actual control) -- how can i do that?

It needs to appear based on conditions.

So let's say if a standard control is filled, then the control created by code needs to appear..and if it's a filled another control that i will create by code needs to appear 

There is no limit to how many controls needed that's why i want it dynamic and not actual controls as they need to appear based on conditions 

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create a dynamic fields in form?

    Hi,

    How to do it by extension and how to override it's lookup?

  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 19,495 Super User 2025 Season 1 on at
    RE: How to create a dynamic fields in form?

    Have a look at the standard tutorial_Form_AddControl form, here is the code below. It demonstrates the basics of how to do add form controls at runtime. Also with events like validate.

    [Form]
    public class tutorial_Form_AddControl extends FormRun
    {
        int  i;
    
        public void run()
        {
            // Create a dummy control to use so all dynamically added controls can register to its override
            FormBuildDesign             formBuildDesign = form.design();
            FormBuildGroupControl       formBuildGroupControl;
            FormStringControl c;
    
            
            ;
            c = addGroup.addControl(FormControlType::String,'runTimeControl');
            c.label("Dummy control");
            c.registerOverrideMethod(methodStr(FormStringControl, validate), 'runTimeControl_validate');
            c.visible(false);
    
            formBuildGroupControl = formBuildDesign.control( addGroup.id() );
            super();
        }
    
        public boolean runTimeControl_validate(FormStringControl stringControl)
        {
            boolean ret;
            ;
    
            ret = stringControl.validate(); // Same as calling super in the control::validate
    
            warning(funcname()   ' Control:'   stringControl.Label()   ' Value:'   stringControl.valueStr());
            return ret;
    
        }
    
        [Control("Button")]
        class Button
        {
            void clicked()
            {
                FormBuildDesign             formBuildDesign = form.design();
                FormBuildGroupControl       formBuildGroupControl;
                FormStringControl c;
                ;
    
                i  ;
                // Add the control - increment control name by 1
                c = addGroup.addControl(FormControlType::String, 'runTimeControl'   int2str(i));
                c.width(300);
    
                // register the controls validate override 
                c.registerOverrideMethod(methodStr(FormStringControl, validate), 'runTimeControl_validate');
                            
                // set the controls label name
                c.label('New Control - runTimeControl'   int2str(i));
    
                formBuildGroupControl = formBuildDesign.control( addGroup.id() );
            }
    
        }
    
    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans