/// <summary> /// Base class for search /// </summary> class searchBaseClass { const private Integer priorityMax = 99; /// <summary> /// Method that searches for values /// </summary> protected void search(//your parmeters) { } /// <summary> /// Method that indicates the class priority and therefor the number in which it is executed /// </summary> /// <returns> /// An integer indicating the class priority and therefor the number in which it is executed /// </returns> protected Priority priority() { return searchBaseClass::PriorityMax; } /// <summary> /// Method that creates a map of search classes to be executed in a priorized way /// </summary> /// <returns> /// A map containing class objects to execute /// </returns> private Map createExecutionMap() { DictClass dictClass; searchBaseClass searchBase; ListEnumerator listEnumerator; List listClass = new DictClass(classnum(searchBaseClass)).extendedBy(); Map mapExecutionClasses = new Map(Types::Integer, Types::Class); listEnumerator = listClass.getEnumerator(); while (listEnumerator.moveNext()) { dictClass = new DictClass(listEnumerator.current()); if (dictClass) { searchBase = dictClass.makeObject(); if (searchBase) { // Add class object to execution list unless the priority is already added if (!mapExecutionClasses.exists(searchBase.priority())) { mapExecutionClasses.insert(searchBase.priority(), searchBase); } else { warning(strFmt("SearchSkipped", dictClass.name(), searchBase.priority())); } } } } return mapExecutionClasses; } /// <summary> /// Method that run through all classes that searches for data /// </summary> public void run() { searchBaseClass searchBase; Map mapExecutionClasses; mapExecutionClasses = this.createExecutionMap(); for (int i = 1; i <= searchBase::priorityMax; i++) { if (mapExecutionClasses.exists(i)) { searchBase = mapExecutionClasses.lookup(i); if (searchBase) { searchBase.search(); } } } } } /// <summary> /// child Class searching /// </summary> class searchChildClass extends searchBaseClass { /// <summary> /// Method that indicates the class priority and therefor the number in which it is executed /// </summary> /// <returns> /// An integer indicating the class priority and therefor the number in which it is executed /// </returns> protected Priority priority() { return 1; } /// <summary> /// Method searching /// </summary> protected void search(//your parmeters) { //your logic }
This blog is contains coding reference related to Microsoft AX 2012 and D365 finance and operations and Power platform
Showing posts with label class. Show all posts
Showing posts with label class. Show all posts
Tuesday, April 23, 2024
Iterate through extended child classes dynamically using X++
Saturday, April 24, 2021
Sysoperations frameworks Tips and tricks in AX
protected ClassDescription defaultCaption() { return "@CashManagement:CashFlowTimeSeriesInitializeControllerCaption"; } public ClassDescription caption() { return this.defaultCaption(); } /// <summary> /// Indicates if the class must run in batch or not. /// </summary> /// <returns> /// Always returns false. /// </returns> /// <remarks> /// This method must be in this class because it is called from the <c>dialogRunbase</c> class. /// </remarks> public boolean mustGoBatch() { return false; } /// <summary> /// Determines whether the job can be executed in batch. /// </summary> /// <returns> /// false if the job cannot be executed in batch; otherwise, true. /// </returns> public boolean canGoBatch() { return false; } /// <summary> /// Sets whether to show the batch tab or not. /// </summary> /// <param name = "_showBatchTab">Flag to identify whether to show the batch tab or not.</param> /// <returns>False for batch tab to be invisible</returns> public boolean showBatchTab(boolean _showBatchTab = showBatchTab) { return false; } public boolean showBatchRecurrenceButton(boolean _showBatchRecurrenceButton = showBatchRecurrenceButton) { return false; }
Sunday, April 11, 2021
Access public variables in extension class using chain of command
When you wrap a method, you can also access public and protected methods and variables of the base class. CustInvoiceJour is a base class variable hence you will be able to access it. Eg. [ExtensionOf(classStr(SalesConfirmJournalCreate))] Final class SalesConfirmJournalCreate_Extension { protected void createJournalHeader() { next createJournalHeader(); //It's as simple as this: custConfirmJour.SalesBalance = 0; } if gets an error, It's an old bug with variable names. Declare new one and use it: protected void createJournalHeader() { next createJournalHeader(); CustConfirmJour custConfirmJourLocal = custConfirmJour; custConfirmJourLocal.MyField = 'blah-blah'; } }
Add new fields in sysoperation dialog and get the values in controller class in AX
UIBuilder class
[ExtensionOf(classstr(ExchangeRateImportUIBuilder))] final class PDPExchangeRateImportUIBuilder_Extension { public FormBuildIntControl intCtrl; public FormBuildCheckBoxControl booleanCtrl; public void build() { next build(); DialogField dialogField; DialogField dialogFieldNoYesId; ExchangeRateImportRequest dataContract1; FormBuildCheckBoxControl exchangeRateFromPreviousDayControl; dataContract1 = this.dataContractObject(); // creating this field if standared code skips it to avoid type cast error in contoller at runtime if(exchangeRateFromPreviousDayControl == null) { dialogField = dialog.addField(extendedtypestr(ExchangeRateFromPreviousDay)); exchangeRateFromPreviousDayControl = dialogField.control(); exchangeRateFromPreviousDayControl.value(dataContract1.parmExchangeRateFromPreviousDay()); exchangeRateFromPreviousDayControl.allowEdit(false); exchangeRateFromPreviousDayControl.visible(false); } dialogField = dialog.addField(extendedtypestr(NumberOf),"integer","integer"); intCtrl = dialogField.control(); intCtrl.value(dataContract1.parmInteg()); dialogField = dialog.addField(extendedtypestr(NoYesId),"boolean","boolean"); booleanCtrl = dialogField.control(); booleanCtrl.value(dataContract1.parmNoYesId()); } }
Contract class
[ExtensionOf(ClassStr(ExchangeRateImportRequest))] [DataContractAttribute] final class PDPExchangeRateImportRequest_Extension { public int integ; public NoYesId noYesValue; /// <summary> /// data memeber attribute of Integ field /// </summary> /// <param name = "_integ">integ</param> /// <returns>int</returns> [DataMemberAttribute] public int parmInteg(int _integ = 0) { if (!_integ) { integ = _integ; } return integ; } /// <summary> /// NoyesId field /// </summary> /// <param name = "_noYesValue">NoYesValue</param> /// <returns>boolean</returns> [DataMemberAttribute] public NoYesId parmNoYesId(NoYesId _noYesValue = NoYes::No) { if (!_noYesValue) { noYesValue = _noYesValue; } return _noYesValue; } }
Controller class
[ExtensionOf(ClassStr(ExchangeRateImportController))] final class PDPExchangeRateImportController_Extension { public const str numberof = 'Fld11_1'; public const str noYesValue = 'Fld12_1'; public void getFromDialog() { next getFromDialog(); FormRun theDialogForm; ExchangeRateImportRequest exchangeRateImportRequest; ExchangeRateProviderFactory factory; FormIntControl intCtrl; FormCheckBoxControl booleanCtrl; FormCheckBoxControl exchangeRateFromPreviousDayControl; exchangeRateImportRequest = this.getDataContractObject(classStr(ExchangeRateImportRequest)); theDialogForm = this.dialog().formRun(); intCtrl = theDialogForm.control(theDialogForm.controlId(numberof)); booleanCtrl = theDialogForm.control(theDialogForm.controlId(noYesValue)); exchangeRateImportRequest.parmInteg(intCtrl.value()); exchangeRateImportRequest.parmExchangeRateTypeRecId(booleanCtrl.value()); Info(strFmt("%1--%2",intCtrl.value(), booleanCtrl.value())); } }
Wednesday, December 16, 2015
Subscribe to:
Posts (Atom)