web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to clear all fields in a form

(0) ShareShare
ReportReport
Posted on by 9,237 Super User 2026 Season 2

Hi all,

I created a new form without any data source (just for calculation purpose), now i want to clear all the fields on the form with the click of a button.

can any one help me, how can i  do this.

Thanks in advance....

Regards

-Harry

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Try this x++ code on button clicked event

    void clicked()
    {
        Args args;
        FormRun formRun;
        ;

        super();

        args = new Args();
        args.object(form);
        formRun = new FormRun(Args);
        formRun.run();
        formRun.detach();

        element.close();
    }

    basically it is initiating a new instance of form giving impression all fields got cleared right away

  • Deepak Agarwal Profile Picture
    9,237 Super User 2026 Season 2 on at

    HI,

    Thanks for reply.

    This code is working fine but a little issue is there this code clear my buffer also which i used to store temporary values. So can i use any other method to clear only fields.

  • Verified answer
    Community Member Profile Picture
    on at

    Then, try with this x++ code on button clicked event

     

    void clicked()

    {

        void clearFormControls(Object o)

        {

            FormBuildControl    formBuildControl;

            FormStringControl   formStringControl;

            FormInt64Control    formInt64Control ;

            FormIntControl      formIntControl ;

            FormRealControl     formRealControl;

            FormTimeControl     formTimeControl;

            FormCheckBoxControl formCheckBoxControl;

            FormDateControl     formDateControl;

            Date                emptyDate;

            int                 i;

            ;

     

            for (i=1;i<=o.controlCount(); i++)

            {

                formBuildControl = o.controlNum(i);

                                              

                switch (ClassId2Name(classIdGet( element.control(formBuildControl.id()))))

                {

                    case 'FormStringControl':

                        formStringControl = element.control(formBuildControl.id());

                        formStringControl.text('');

                        break;

                    case 'FormIntControl':

                        formIntControl = element.control(formBuildControl.id());

                        formIntControl.value(0);

                        break;

                    case 'FormInt64Control':

                        formInt64Control = element.control(formBuildControl.id());

                        formInt64Control.value(0);

                        break;

                    case 'FormRealControl':

                        formRealControl = element.control(formBuildControl.id());

                        formRealControl.realValue(0);

                        break;

                    case 'FormTimeControl':

                        formTimeControl = element.control(formBuildControl.id());

                        formTimeControl.value(0);

                        break;

                    case 'FormCheckBoxControl':

                        formCheckBoxControl = element.control(formBuildControl.id());

                        formCheckBoxControl.value(0);

                        break;

                    case 'FormDateControl':

                        formDateControl = element.control(formBuildControl.id());

                        formDateControl.dateValue(emptyDate);

                        break;

                }

     

                if (formBuildControl.isContainer())

                    clearFormControls(formBuildControl);

            }

        }

        ;

     

        super();

        clearFormControls(form.design());

    }

     

  • Deepak Agarwal Profile Picture
    9,237 Super User 2026 Season 2 on at

    HI,

    Thanks for your reply, this code is working absolutely fine....

    Thanks again...

    Regards

    -Harry

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans