Monday, September 14, 2020

Filtering drop down list based on another drop down on Dialog in Ax 2012 using X++

 Hi guys, Today we see how to Filtering drop down list based on another drop down.

In SysOperation we have to write code in 4 classes.

1.Contract class.

2.Controller class.

3.Service class.

4.UI builder class.


Contract class:

Mainly Contract class is for parameter Declaration Through Parm Methods.We set any Default values we implement with SysOperationInitializable. Before that we have to use SysOperationAlwaysInitializeAttribute.

For any validations we have to implement with SysOperationValidatable.


Class Declaration:

[DataContractAttribute,SysOperationAlwaysInitializeAttribute, SysOperationContractProcessingAttribute(classStr(CustDetailsUiBuilder))] public class CustDetailsContract implements SysOperationInitializable,SysOperationValidatable { CustGroupId custGroup; AccountNum accountNum; }

Parm Method1:

[DataMemberAttribute('AccountNum'), SysOperationLabelAttribute('AccountNum'), SysOperationHelpTextAttribute('AccountNum.')] public AccountNum parmAccountNum(AccountNum _accountNum= accountNum) { accountNum = _accountNum; return accountNum; }

Parm method 2:

[DataMemberAttribute('CustGroup'), SysOperationLabelAttribute('CustGroup'), SysOperationHelpTextAttribute('CustGroup.')] public CustGroupId parmCustGroup(CustGroupId _custGroup= custGroup) { custGroup = _custGroup; return custGroup; }

initialize method:

public void initialize() { custGroup='10'; accountNum=' '; }

validate method:

public boolean validate() { CustTable custTable; if(this.parmAccountNum()) { custTable=CustTable::find(this.parmAccountNum()); if (!custTable) { return checkFailed('Enter Valid accountNum'); } } else { return checkFailed('Please Enter accountNum'); } return true; }

UiBuilder Class:

    This class is mainly used for User interface Dialog changes. If we want add any lookup,enable or disable, add fields to group.


Class Declaration:

public class CustDetailsUiBuilder extends SysOperationAutomaticUIBuilder { DialogField dialogCustGroup; DialogField dialogAccountNum; CustDetailsContract contract; }

build method:

public void build() { Dialog dialogLocal = this.dialog(); contract = this.dataContractObject(); dialogLocal.addGroup('Customer Id'); this.addDialogField(methodStr(CustDetailsContract,parmAccountNum), contract); dialogLocal.addGroup('Customer Group'); this.addDialogField(methodStr(CustDetailsContract,parmCustGroup), contract); } Modified method: public boolean custGroupModified(FormStringControl _control) { dialogCustGroup.value(_control.valueStr()); return true; }

lookup method: public void lookupAccountNum(FormStringControl _control) { Query query = new Query(); SysTableLookup sysTablelookup; sysTablelookup =SysTableLookup::newParameters(tableNum(CustTable),_control); sysTablelookup.addLookupfield(fieldNum(CustTable,AccountNum)); sysTablelookup.addLookupfield(fieldnum(CustTable,Party)); query.addDataSource(tableNum(CustTable)); query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, CustGroup)).value(dialogCustGroup.value()); sysTablelookup.parmQuery(query); sysTablelookup.performFormLookup(); }

lookup method: public void lookupCustGroup(FormStringControl _control) { SysTableLookup sysTablelookup; sysTablelookup =SysTableLookup::newParameters(tableNum(CustGroup),_control); sysTablelookup.addLookupfield(fieldNum(CustGroup,CustGroup)); sysTablelookup.addLookupfield(fieldnum(CustGroup,Name)); sysTablelookup.performFormLookup(); }

postBuild:

public void postBuild() { super(); dialogCustGroup = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(CustDetailsContract,parmCustGroup)); //if (dialogCustGroup) //{ // dialogCustGroup.lookupButton(2); //} dialogCustGroup.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(CustDetailsUiBuilder, lookupCustGroup), this); dialogCustGroup.registerOverrideMethod(methodStr(FormStringControl, modified),methodStr(CustDetailsUiBuilder, custGroupModified), this); dialogAccountNum = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(CustDetailsContract,parmAccountNum)); dialogAccountNum.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(CustDetailsUiBuilder, lookupAccountNum), this); //if (dialogAccountNum) //{ // dialogAccountNum.lookupButton(2); //} }

Controller class:

    Main logic We have to written in Controller class.

Class Declaration:

public class CustDetailsController extends SysOperationServiceController { }

new method: public void new() { super(); this.parmClassName(classStr(CustDetailsService)); this.parmMethodName(methodStr(CustDetailsService, process)); } main method: public static void main(Args args) { CustDetailsController controller; controller = new CustDetailsController(); controller.startOperation(); }

Service method:
                    We can write our own logic in Service class.

Class Declaration:

public class CustDetailsService extends SysOperationServiceBase { } process method: public void process(CustDetailsContract _contract) { CustTable custTable; AccountNum accountNum; CustGroupId custGroup; accountNum = _contract.parmAccountNum(); custGroup = _contract.parmCustGroup(); //custTable=CustTable::find(accountNum,true); select forupdate custTable where custTable.AccountNum == accountNum; ttsbegin; custTable.CustGroup=custGroup; custTable.doupdate(); ttscommit; info(strFmt('CustGroup - %1 is updated for %2-Customer',

                custTable.CustGroup, custTable.AccountNum)); }



OutPut:



Based on CustGroup Account number is filterd.





Keep Daxing!!

No comments:

Post a Comment