Dynamics 365 FO - Create number sequence
Nghia Song - Microsoft Dynamics 365 Technical Consultant
Nghia Song
Tel - WhatsApp: +84967324794
Email: songnghia.uit@gmail.com
Create number sequence
Step | Screenshots | Description |
0 | Start Visual Studio using Run as administrator. | |
1 | Create number sequences for letter id: - How to use number sequences? - You need to write some code to create setup number sequences for letter id - You need to setup number sequences code to assign for letter id | |
2 | Create class extension from NumberSeqModuleCustomer | |
3 | public void loadModule_Extension() { NumberSeqDatatype dataType = NumberSeqDatatype::construct();
datatype.parmDatatypeId(extendedTypeNum(NVWEmplID)); datatype.parmReferenceHelp("Employee ID"); datatype.parmWizardIsContinuous(false); datatype.parmWizardIsManual(NoYes::No); datatype.parmWizardIsChangeDownAllowed(NoYes::Yes); datatype.parmWizardIsChangeUpAllowed(NoYes::Yes); datatype.parmWizardHighest(999999); datatype.parmSortField(20); datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype); } | AX has many class name like: NumberSeqModule…. With … is module name I will create number sequences for letter id in module Project, so I open class NumberSeqModuleProject Extend the class NumberSeqModuleVendor: Create method LoadModule_Extension () and write some code like screenshot |
3.1 | [ExtensionOf(classStr(NumberSeqModuleVendor))] public final class NumberSeqModuleVendor_Extension { public void loadModule_Extension() { NumberSeqDatatype dataType = NumberSeqDatatype::construct();
datatype.parmDatatypeId(extendedTypeNum(NVWEmplID)); datatype.parmReferenceHelp("Number seq for Employee ID"); datatype.parmWizardIsContinuous(false); datatype.parmWizardIsManual(NoYes::No); datatype.parmWizardIsChangeDownAllowed(NoYes::Yes); datatype.parmWizardIsChangeUpAllowed(NoYes::Yes); datatype.parmWizardHighest(999999); datatype.parmSortField(20); datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype); } /// <summary> /// Add our module to map /// </summary> /// <param name = "_numberSeqModuleNameMap">Map</param> [SubscribesTo(classStr(NumberSeqGlobal), delegateStr(NumberSeqGlobal,buildModulesMapDelegate))] static void buildModulesMapSubscriber(Map _numberSeqModuleNameMap) { NumberSeqGlobal::addModuleToMap(classNum(NumberSeqModuleVendor), _numberSeqModuleNameMap); } /// <summary> /// return Number Sequence Reference from EDT /// </summary> /// <returns>numberSequenceReference</returns> static numberSequenceReference numRefMSWHSRouteId() { return NumberSeqReference::findReference(extendedTypeNum(NVWEmplID)); } /// <summary> /// Return our module - WHS /// </summary> /// <returns>NumberSeqModule</returns> public NumberSeqModule numberSeqModule() { next numberSeqModule();
return NumberSeqModule::Vend; } } | Full code extension |
4 | [ExtensionOf(tableStr(VendParameters))] public final class VendParameters_Extension { public server static NumberSequenceReference numRefNVWEmployeeID() { return NumberSeqReference::findReference(extendedTypeNum(NVWEmplID)); } } | You need to add one function to get number sequences number in VendParameters table Why add code to VendParameters table? Because you choose module AccountPayable, so you should add this code to VendParameters |
5 | After the job is executed, run Number Sequence Wizard. Path: Account payable > Number Sequence | |
6 | [Form] public class NVWEmployee extends FormRun { NumberSeqFormHandler numberSeqFormHandler; public NumberSeqFormHandler numberSeqFormHandler() { if(!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm(VendParameters::numRefNVWEmployeeID().NumberSequenceId, element,NVWEmployee_ds,fieldNum(NVWEmployee, NVWEmplID)); } return numberSeqFormHandler; } [DataSource] class NVWEmployee { /// <summary> /// /// </summary> /// <param name = "_append"></param> public void create(boolean _append = false) { element.numberSeqFormHandler().formMethodDataSourceCreatePre(); super(_append); element.numberSeqFormHandler().formMethodDataSourceCreate(); } /// <summary> /// /// </summary> public void delete() { ttsBegin; element.numberSeqFormHandler().formMethodDataSourceDelete(); super(); ttsCommit; } /// <summary> /// /// </summary> /// <returns></returns> public void write() /// <summary> /// /// </summary> /// <returns></returns> public boolean validateWrite() { boolean ret; ret = super(); ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret; return ret; } /// <summary> /// /// </summary> public void linkActive() { element.numberSeqFormHandler().formMethodDataSourceLinkActive(); super(); } } } | Some code in the form to generate the number seq |
7 | Now you need to load module? What is it? Load module means load one setup number sequences for letter id, how to do it? We will create job to call class NumberSeqModuleVendor | |
8 | class NVWNumberSeqJob { public static void main(Args _args) { NumberSeqModuleVendor numberSeqMod = new NumberSeqModuleVendor(); numberSeqMod.loadModule_Extension(); info("Create new rule for number seq"); } } | Run this job |
9 | Then you can seee the number seq in the parameter of module | |
10 | We can setup new format of number seq | |
11 | Create new format of num seq | |
12 | Set new format to number seq | |
13 | And this is result | |
No comments:
Post a Comment