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, ...
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,345 Super User 2025 Season 2 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

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans