Skip to main content

Notifications

Announcements

No record found.

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 8,575

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

  • Deepak Agarwal Profile Picture
    8,575 on at
    Re: How to clear all fields in a form

    HI,

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

    Thanks again...

    Regards

    -Harry

  • Verified answer
    Community Member Profile Picture
    on at
    Re: How to clear all fields in a form

    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
    8,575 on at
    Re: How to clear all fields in a form

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    Re: How to clear all fields in a form

    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

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Kempeth Profile Picture

Kempeth 4

#1
Andy Adamak Profile Picture

Andy Adamak 4

#1
Community Member Profile Picture

Community Member 4

Featured topics

Product updates

Dynamics 365 release plans