Dynamics Ax Disable / Enable all datasource fields

Sometimes you want to disable all fields on a form’s datasource and enable some of them afterwards. Put the following piece of code in the Global class and you can call it from wherever you like.

public static void LIBSetAllTableFields(FormDataSource _formDataSource,Boolean _value)
{
    DictTable       dictTable = new DictTable(_formDataSource.table());
    int             i;
    int             fieldNumber;
    ;
    for(i = 1;i < = dictTable.fieldCnt();i++)
    {
        fieldNumber = dictTable.fieldCnt2Id(i);
        if(_formDataSource.object(fieldNumber))
        {
            _formDataSource.object(fieldNumber).allowEdit(_value);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *