Enable/Disable form control (COC) in X++

 

Purpose:

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

Product:

Dynamics 365 for Finance and Operations, Platform Update 9.

Development approach:

Customization through extension. we need to show workflow related fields in VendInvoiceJournal   list page when a transaction enabled with workflow toggle.

Development:

  1. Create a COC of a standard form method enabling/disabling the form controls. In this case, we are creating a COC of a standard method  VendInvoiceJournal  form.
  2. Please find the COC method definition as follows.
I had four custom controls already added in my form through extension and enabled Auto declaration = YES for all controls


[ExtensionOf(formDataSourceStr(VendInvoiceJournal, VendInvoiceJour))]
final class VendInvoiceJournal_Extension
{
     public int active()
     {
         int ret;
         next active();
         /// to get current record
         VendInvoiceJour vij = this.cursor();

          //The workflow fields based on workflow icon on header should be visible only if there is a workflow history available this invoice
         VendInvoiceInfoTable localvendInvoiceInfoTable =         VendInvoiceInfoTable::findSourceDocumentHeader(vij.SourceDocumentHeader);
         // to get form controls through foem run
         FormRun formrun = this.formRun() as FormRun;
// enables if workflow is attached for particular invoice
         if (Workflow::findTrackingStatusForDocument(localvendInvoiceInfoTable))
         {
            var subby =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_SubmittedBY));
             var subdate =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_SubmittedDate));
             var appdate =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_AprrovedDate));
             var appby =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_AprrovedBY));
             subby.visible(true);
             subdate.visible(true);
             appdate.visible(true);
             appby.visible(true);

         }
         else
         {
             var subby =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_SubmittedBY));
             var subdate =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_SubmittedDate));
             var appdate =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_AprrovedDate));
             var appby =  formrun.design().controlName(formControlStr(VendInvoiceJournal, VendInvoiceJour_AprrovedBY));
             subby.visible(false);
             subdate.visible(false);
             appdate.visible(false);
             appby.visible(false);
         }
         return ret;
     }
}

Comments