How to disable fields of form datasource in AX 2012

Hi All,

The correct approach is
DataSourceName_ds.object(fieldnum(Table, Field)).enabled(true/false);

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

The Incorrect approach is
ControlName.enabled(true/false);

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

DataSourceName_ds.allowEdit(false);

e.g.,
SalesLine_ds.allowEdit(false);

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);
}
}
}

How to make a control editable:
Incorrect : ControlName.allowEdit(true/false);
Correct : DataSourceName_ds.object(fieldnum(Table, Field)).allowEdit(true/false);
How to make a control mandatory:
Incorrect : ControlName.mandatory(true/false);
Correct : DataSourceName_ds.object(fieldnum(Table, Field)).mandatory(true/false);

Till then, Happy Daxing………..

Advertisements

2 responses

  1. this post is very useful for starting level devlopers and me.
    keep it up.

    Liked by 1 person

    1. Dear raziq:

      Thank you so much

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: