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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to create a dynamic fields in form?

(0) ShareShare
ReportReport
Posted on by 1,552

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 

I have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,678 Super User 2026 Season 1 on at

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

  • junior AX Profile Picture
    1,552 on at

    Hi,

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 681

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 448 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 218 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans