Friday, 27 March 2015

Enabling and disabling fields in a grid based on enum values in AX 2012

AcqMethod is Combobox control whose auto declaration is made yes.
AcqMethod has two enum values AcquisitionAmt and AcquisitionAdjustmentAmount .

AcquisitionAmt and AcquisitionAdjustmentAmount mentioned in the code are the names of the fields in grid whose auto declaration property is yes.

Override the active method of the grid datasource and write the following code :

if(AcqMethod.selection() == 0)
    {
         AcquisitionAmt.enabled(true);
         AcquisitionAdjustmentAmount.enabled(false);
    }
    else if(AcqMethod.selection() == 1)
    {
         AcquisitionAmt.enabled(false);
         AcquisitionAdjustmentAmount.enabled(true);
    }

The same way if you need to disable complete record based on the enum values then :

if(AssetTransSecCur.Updated == NoYes::Yes)
    {
        AssetTransSecCur_ds.object(fieldNum(AssetTransSecCur, TransDate)).allowEdit(false);
        AssetTransSecCur_ds.object(fieldNum(AssetTransSecCur, AcquisitionAmt )).allowEdit(false);
        Update.enabled(false);
}


NOTE :

Update is a button with auto declaration yes.
AssetTransSecCur is the datasource name.

No comments:

Post a Comment