AX7/D365/Operations: Enable/Disable form control in X++

Purpose:

The purpose of this document is to demonstrate how we can enable/disable a form control in X++ based on a business logic.

Product:

Dynamics 365 for Finance and Operations, Platform Update 9.

Development approach:

Customization through extension.

Development:

  1. Create a post event handler of a standard form method enabling/disabling the form controls. In this case, we are creating a post event handler of a standard method setFieldAccessHeader of SalesQuotationProjTable form.
  2. Please find the event handler method definition as follows.
[PostHandlerFor(formStr(SalesQuotationProjTable), formMethodStr(SalesQuotationProjTable, setFieldAccessHeader))]
public static void SalesQuotationProjTable_Post_setFieldAccessHeader(XppPrePostArgs args)
{
    FormRun             sender = args.getThis();
    FormDataSource      salesQuotationTable_ds;
    SalesQuotationTable salesQuotationTable;

    salesQuotationTable_ds = sender.dataSource(1);
    salesQuotationTable = salesQuotationTable_ds.cursor();

    sender.control(sender.controlId(formControlStr(SalesQuotationProjTable, DeviceUsageGroup))).enabled((salesQuotationTable.AMDeviceId) ? true : false);
}
Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s