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 :
Microsoft Dynamics AX (Archived)

How to clear all fields in a form

(0) ShareShare
ReportReport
Posted on by 8,602

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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans