Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

FormBuildGroupControl: editable

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: FormBuildGroupControl: editable

    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.

  • Martina Bergamo Profile Picture
    Martina Bergamo 1,470 on at
    RE: FormBuildGroupControl: editable

    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...

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: FormBuildGroupControl: editable

    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
    Martina Bergamo 1,470 on at
    RE: FormBuildGroupControl: editable

    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?

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: FormBuildGroupControl: editable

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans