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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Disable all controls on any form through code

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm trying to disable all the controls on any form that is opened. 

We have a class that is called, and it goes and checks the setup of which menu item to use for the formRun and also checks user group.  Then if a user is not in the user group, they should be able to open the form, but they should not be able to click on any of the buttons, or edit anything on the form.

I have tried the following but it doesn't seem to work:

        for (i = 1; i <= formRun.form().design().controlCount(); i++)
        {
            control = formRun.form().design().controlNum(i);
            control.enabled(false);
            this.disableControls(control);
        }

The disableControls method does the same thing but is called recursively.  When I debug the code, the value for Enabled is changed to "No", yet when I look at the form all controls are still enabled.

Is there another way perhaps to perform this?

Thanks,

Dyls

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sohaib Cheema Profile Picture
    48,893 User Group Leader on at
    RE: Disable all controls on any form through code

    Kindly use follwoing method

    void lockControls(Object o,str name)
    {
        FormBuildControl  formBuildControl;
        int i;
        ;
        
        for (i=1;i<=o.controlCount(); i++)
        {
            formBuildControl = o.controlNum(i);
            element.control(formBuildControl.id()).enabled(false);
        }
    }

    //calll this above method from run method of form as under:

    void run()
    {
        super();
        this.lockControls(form.design(),"The form");
    }

  • Community Member Profile Picture
    on at
    RE: Disable all controls on any form through code

    Hi Sohaib,

    Thank you for your reply.  

    Unfortunately I won't be able to go this route.  The reason is that I would have to change all the forms in AX, including any new custom developed forms.  We have setup tables where the users can set up any menu items to open in a process (through a class).  It's completely configurable, so we won't know what they would want to have open.

    We are able to make the DataSources on the forms read-only by doing the following:

       for (i = 1; i <= formrun.form().dataSourceCount(); i++)

       {

           if (formrun.form().dataSource(i).allowEdit())

           {

               formrun.form().dataSource(i).allowEdit(!this.isReadOnly());

           }

       }

    The users aren't able to edit any information on the form, but when they click on any button that opens another form, or has any code behind it that performs any processing, etc... I need to prevent that.

  • Anton Venter Profile Picture
    20,301 Super User 2025 Season 2 on at
    RE: Disable all controls on any form through code

    Hi Dylan, you say that the controls get disabled in code but when the form is displayed the controls are enabled. Where do you have your code to disable the datasources and controls? SysSetupFormRun class?

  • Community Member Profile Picture
    on at
    RE: Disable all controls on any form through code

    Hi Anton,

    It's one of our custom classes that we developed.

  • Verified answer
    Anton Venter Profile Picture
    20,301 Super User 2025 Season 2 on at
    RE: Disable all controls on any form through code

    Hi Dylan, the SysSetupFormRun class is called for every form in the AOT that is opened from the AX client. You could put your code to control access to the form controls in the init or run method of the SysSetupFormRun class.

  • premjitsaha Profile Picture
    on at
    RE: Disable all controls on any form through code

    how to create the void lockcontrols method in a class?

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Disable all controls on any form through code

    Right click > New method, or override existing ones.

    You can read all about it here:

    msdn.microsoft.com/.../aa673265.aspx

  • premjitsaha Profile Picture
    on at
    RE: Disable all controls on any form through code

    I already know that.

    I need to know how to convert this method of  form to a class as it has element.control which cannot be used in classes

    void lockControls(Object o,str name)

    {

       FormBuildControl  formBuildControl;

       int i;

       ;

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

       {

           formBuildControl = o.controlNum(i);

           element.control(formBuildControl.id()).enabled(false);

       }

    }

  • David Massey Profile Picture
    on at
    RE: Disable all controls on any form through code

    This sounds like you are trying to re-implement what security duties/roles/privileges are defined to do for you.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Disable all controls on any form through code

    You have to pass in FormRun object, which is the "element". And in the method you replace element with _formRun, as the method's caller parameter.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans