Tuesday, October 8, 2019

D365 Do not disable form controls - disable the datasource fields!

When developing forms in Microsoft Dynamics 365 for Operations you sometimes want to disallow the user to edit some of the forms fields. The typical approach is to turn on Auto Declaration on the form controls and diasable them using:
FormControl.allowEdit(false);

The problem with this approach is that the same field might be exposed more than once in your design, for instance both in the grid view and in the details view. Also, users adding fields via Personalization might pose challenges. In order to make sure the user is not allowed to edit the data, use this approach:
Datasource_ds.object(fieldNum(tablename, fieldname)).allowEdit(false);

Similarly you can enable/disable the fields if this is your business requirement. This will make it more evident for the user that the field is not editable:
Datasource_ds.object(fieldNum(tablename, fieldname)).enabled(false);

No comments:

Post a Comment