Microsoft Dynamics AX development

Archive for March, 2017

SrsReportDataContractUIBuilder: Enable/disable button depend on a flag

Scenario:
I have to create a dialog with SrsReportDataContractUIBuilder with:

  • a flag “MyFlag”
  • a button “MyButton”

When the flag is active, I have to disable the button.
When the flag is not active, I have to enable the button.

Create the UIBuilder class:

class MyUIBuilderClass extends SrsReportDataContractUIBuilder
{
    MyClassNameContract       contract;
    FormBuildButtonControl    myButton;
    DialogField               myFlag;
}

In the postBuild method, initialize the dialog with the controls:

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

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

myFlag = this.addDialogField(methodStr(MyClassNameContract, parmMyFlag), 
                             contract);

dialogGroup = dialogLocal.addGroup('My group name');
groupBuildControl = dialogLocal.formBuildDesign().control(
                    dialogGroup.formBuildGroup().id());
buttonBuildControl = groupBuildControl.addControl(FormControlType::Button, 
                     'My button name');

super();

myButton.text(literalStr("A text for my button"));

//if you want to add a method for the button
myButton.registerOverrideMethod(methodStr(FormButtonControl, clicked), 
         methodStr(MyUIBuilderClass, methodForTheButton), this);

myFlag = this.bindInfo().getDialogField(this.dataContractObject(), 
         methodStr(MyClassNameContract, parmMyFlag));
myFlag.value(true);
myFlag.registerOverrideMethod(methodStr(FormChecKBoxControl, modified), 
       methodStr(MyUIBuilderClass, enableDisableMyButton), this);

buttonBuildControl.enabled(!myFlag.value());

 

In the method enableDisableMyButton:

public boolean enableDisableMyButton(FormCheckBoxControl _checkBoxControl)
{
    int ctrlId          = dialog.formRun().controlId('My button name');
    FormControl control = dialog.formRun().control(ctrlId);

    control.enabled(!_checkBoxControl.checked());

    return true;
}

 

Insert the logic to bind the UIBuilder to the contract class, in the attributes:

[
     DataContractAttribute,
     SysOperationContractProcessingAttribute(
        classstr(ReturnAcknowledgmentAndDocUIBuilderWPC))
]

Tag Cloud