Saturday, June 6, 2020

Applying validation on fields (methods) in dialog form in Ax 2012

1. go to class declaration and make the following "FormBulidStringControl"

FormBuildStringControl                  controlFromDataAreaId,controlToDataAreaId,controlGeneralType,controlMainAccounts,controlDivision;





2. now in the "dialog" method write the following method,below the field where we enter value

controlFromDataAreaId = dlgFromDataAreaId.control();





3. now in the ""dialogPostRun" method write the following code

controlFromDataAreaId.registerOverrideMethod(methodStr(FormStringControl,Validate),
                                            methodStr(TTC_EOM,fromtoEntity_Validate),
                                            this);





4. now make a new method, in this case ""fromtoEntity_Validate

public boolean fromtoEntity_Validate(FormStringControl  _control)
{
    boolean ret         = _control.validate();

    select DataArea from companyInfo
        where companyInfo.DataArea  == _control.valueStr();

    if(companyInfo)
    {
        ret = true;
    }
    else
    {
        ret = ret && checkFailed("Entity does not exist");
    }
    return ret;
}