Thursday, January 10, 2013

Ax 2009 Enable disable field controls

 
The following code can be used to enable all disable field controls in a group control.
Add the field to a container which needs to be enabled are disabled and call the generic function. In the below example, Name is a group control and 2 fields in this control needs to be enabled.

    //[TabPage:General]\[Group:Column1]\[Group:Name]
    Name.enabled(true);
    conItemChildNames = connull();
    conItemChildNames = ["Name_AA_MasterkeyType","Name_M_txtDefault"];
    element.AA_enableDisableFieldControls(Name,conItemChildNames,true);
    conItemChildNames = connull();

void AA_enableDisableFieldControls(FormGroupControl _formGroupControl, 
container _conChildNames, boolean _enableControl = false)
{
    FormGroupControl    formGroupControl;
    Object              fat;
    Object              child;
    Object              bchild;
    int                 controlCount;
    int                 j;
    ;


    formGroupControl = _formGroupControl;
    fat = form.design().control(formGroupControl.id());
    controlCount = fat.controlcount();
    for (j = 1; j <= controlCount; j++)
    {

        bchild  = fat.controlNum(j);
        child = element.design().control(bchild.id());
        if(!conFind(_conChildNames,child.name()))
        {
            child.enabled(_enableControl);
        }
    }
}