16 Dec 2013

Disable/enable form elements + AX 2012

 how you can disable a form element, based on the value of another form element.

As example, the CustTable form will be used. The example will disable the One-time customer checkbox on the General tab if the Mandatory credit limitcheckbox is checked on the same General tab.

Change form properties

  1. Select the Administration Field Group on the TabGeneral TabPage and set the AutoDataGroup Property to No.
  2. Select the Administration_OneTimeCustomer CheckBox field in the Field Group Administration and set the AutoDeclaration property to Yes.



create from methods for enable/disable

Create a new form method setAccessOneTimeCustomer:
void setAccesssOneTimeCustomer()     
{ 
   if (CustTable.MandatoryCreditLimit)     
    { 
       Administration_OneTimeCustomer.enabled(false);    
    } 
    else     
    { 
        Administration_OneTimeCustomer.enabled(true);     
    } 
    custTable_DS.refresh();    
}


call the form methods in active and modified methods

Call the newly created form method in the active method on the Data Sourceof the Form. As such, the second field will be enabled or disabled appropriately upon scrolling through the form.

public int active() 

{   
    int ret; 
    element.setAccesssOneTimeCustomer(); 
    ret = super(); 
    return ret; 
}


Call the newly created form method in the modified method on the field which should trigger the enabling or disabling. In our example, it is the fieldMandatoryCreditLimit. As such the second field, in our case OneTimeCustomerwil be enabled or disabled each time the value of MandatoryCreditLimit is changed.

public void modified()   
{ 
    element.setAccesssOneTimeCustomer();     
    super(); 
}


checkout

Open the CustTable form: check the field Mandatory credit limit: the field One-time customer will be disabled immediately.



No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...