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)

FormBuildGroupControl: editable

(0) ShareShare
ReportReport
Posted on by 1,470

Hi to all!

I have created an UIBuilder for a contract class.

In the postBuild method, I've decleared a new FormBuildGroupControl (I want to add a button to my dialog):

Dialog                  dialogLocal;
Form                    form;
DialogGroup             dialogGroup;
FormBuildGroupControl   groupBuildControl;

super();

dialogLocal             = this.dialog();
contract                = this.dataContractObject() as MyContractClass;
form                    = this.dialog().form();

usePrintManagement      = this.addDialogField(methodStr(MyContractClass, parmMyFlag), contract);
dialogGroup = this.dialog().addGroup(#ButtonName); 
groupBuildControl = this.dialog().formBuildDesign().control(dialogGroup.formBuildGroup().id());
buttonBuildControl = groupBuildControl.addControl(FormControlType::Button, #ButtonName);
myFlag = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(myContractClass, parmMyFlag));
myFlag.registerOverrideMethod(methodStr(FormChecKBoxControl, modified), methodStr(myContractClass, myMethodOnModifiedFlag), this);

When I click on "myFlag" I want to activate/deactivate my buttonBuildControl.

Here the code of "myMethodOnModifiedFlag"

public boolean myMethodOnModifiedFlag(FormCheckBoxControl _checkBoxControl)
{
    buttonBuildControl.enabled(any2enum(!_checkBoxControl.checked()));
    return true;
}


But it does not work...any ideas?

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    First of all, collect more information about what happens. Does your method gets called at all? That's a very important piece; you should follow very different directions depending on the answer.

    By the way, this is a strange piece of code: buttonBuildControl.enabled(any2enum(!_checkBoxControl.checked())). If you believe that it's necessary to convert the value to boolean, using the exclamation mark makes no sense, because it would have to convert the value to boolean even before your conversion. In fact, both enabled() and checked() use the same type (boolean), therefore no conversion is needed.

  • Martina Bergamo Profile Picture
    1,470 on at

    Hi Martin! Thank you for the answer.
    I've changed my code from buttonBuildControl.enabled(any2enum(!_checkBoxControl.checked())) to buttonBuildControl.enabled(!_checkBoxControl.checked())
    I've put a breakpoint and the method gets called.
    With the debugger I've seen the ButtonBuildControl properties, and the property "Enabled" ist set correctly (with Yes/No).
    What I'm doing wrong?

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    The key problem with your code seems to be that you're trying to use form build controls when the form already runs. It would work for setting property values before executing the form, but after that build controls aren't used anymore.

    You could use something like the following code, although it would clearly need some improvements before using in production. Note that I'm using a standalone class for simplicity, not a UI builder.

    class DialogTest
    {
        Dialog dialog;
        FormBuildButtonControl buttonBuildControl;
    
    
        public void new()
        {
            dialog = new Dialog();
        }
    
        public static void main(Args _args)
        {
            new DialogTest().run();
        }
    
        private void run()
        {
            DialogField myFlag = dialog.addField(extendedTypeStr(NoYesId));
            myFlag.registerOverrideMethod(methodStr(FormCheckBoxControl, modified), methodStr(DialogTest, myMethodOnModifiedFlag), this);
    
            // Just a random menu item for demonstration
            dialog.addMenuItemButton(MenuItemType::Display, menuitemDisplayStr(Batch));
    
            dialog.run();
        }
    
        public boolean myMethodOnModifiedFlag(FormCheckBoxControl _checkBoxControl)
        {
            int ctrlId = dialog.formRun().controlId('MnuItm_1');
            FormControl control = dialog.formRun().control(ctrlId);
    
            control.enabled(!_checkBoxControl.checked());
    
            return true;
        }
    }

    Note that normal buttons (not menu item buttons) don't seem to be supported by the dialog class at several places, such as in Dialog::addControls().

    In general, dialogs are intended for input fields. If you need things like buttons, maybe you should be using a normal form.

    By the way, your code above seem to be using the same name for two controls (the group and the button).

  • Martina Bergamo Profile Picture
    1,470 on at

    Thank you Martin!

    I've solved the problem!

    The only change I've made is to put the following code

    int ctrlId = dialog.formRun().controlId('OMSPrint');
    FormControl control = dialog.formRun().control(ctrlId);
    
    control.enabled(!_checkBoxControl.checked());
    

    instead of buttonBuildControl.enabled(!_checkBoxControl.checked());

    I think that the problem was that the UIBuilder does not recognize my buttonBuildControl.

    Why? I don't know...

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    That's what I tried to explain. Build controls are used when designing the form, not when it already runs. Look at which type you get from dialog.formRun().control() - it's not FormBuildButtonControl at all, it should be corresponding runtime control, FormButtonControl.

    Changing build controls won't make any effect unless you use them to construct a new form (when they will be used to initialize the actual runtime controls).

    As I also mentioned, I think that using a normal button won't work in all cases, such as opening the dialog from server.

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans