Disabling fields of a form data-source in dynamics ax

Description:-

Note:- I am using SalesLine as my DataSource of the form for instance.
If you want to disable only two fields of the DataSource, you can disable them like this.

SalesLine_ds.object(fieldNum(SalesLine, SalesPrice).allowEdit(false);
SalesLine_ds.object(fieldNum(SalesLine, LinePercent).allowEdit(false);

If you want to disable all the fields of a DataSource, it is simple by using the below statement.

SalesLine_ds.allowEdit(false);

But, when you want to disable all the fields except two fields in some table like salesLine with many fields, you can’t do it with the above approaches. 
You have to manually disable each and every field of the table or you can simply use below approach.

public static void SetAllTableFields()
{
  DictTable       dictTable = new DictTable(SalesLine.TableId);
  int             i;
  int             fieldNumber;
  ;
  for(i = 1;i < = dictTable.fieldCnt();i++)
  {
    fieldNumber = dictTable.fieldCnt2Id(i);
    if(SalesLine_Ds.object(fieldNumber) &&fieldNumber != fieldNum(SalesLine, LinePercent)
        &&  fieldNumber != fieldNum(SalesLine, SalesPrice))
    {
        SalesLine_Ds.object(fieldNumber).allowEdit(false);
    }
  }
}

Related Posts

Previous
Next Post »

Thanks for comments.....