Reputation: 21
How can we disable and enable fields on a X++ form Dynamics AX ?
Field1 is an enum with option option1 and option2.
We have below scenarios:
If Field1 is option1 then Field2 field should be enabled and Field3 field should be disabled/readonly
If Field1 is option2 then Field3 field should be enabled and Field2 should be disabled/readonly
3/ Also, when the form loads, for the existing records the Field3 and Field2 fields should be enabled/readonly based on their current value for Field1
Upvotes: 1
Views: 13356
Reputation: 6778
You can override method active()
on the form's datasource, something like
public int active()
{
FormDataSource fds;
int ret;
ret = super();
fds = this.dataSource();
fds.object(fieldNum(MyTableName, Field2)).allowEdit(MyDataSourceName.Field1 == option1);
fds.object(fieldNum(MyTableName, Field3)).allowEdit(MyDataSourceName.Field1 == option2);
return ret;
}
That's good enough if Field1
value cannot be modifed by the user. If it can be modified then it makes sense to create a new method e.g. setFieldAccess()
with the logic similar to the above, and call this new method both from the datasource active()
method and from the modified()
method of the datasource field Field1
.
Upvotes: 1