Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

15,483 views

Published on

This lab explain how to use the Number Sequence Framework in Microsoft Dynamics AX2012. It gives a step by step guide to do common tasks when hadling number sequences :
- Describe how to create a new number sequence
- Describe how to use number sequence in Form
- Describe how to use number sequence in X++

Like and share and comment, and see you next lab!

Published in: Technology

Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

  1. 1. Microsoft Dynamics® AX 2012 Number sequence framework
  2. 2. Objectifs • Describe how to create a new number sequence • Describe how to use number sequence in Form • Describe how to use number sequence in X++
  3. 3. how to create a new number sequence?
  4. 4. How to create number sequences?
  5. 5. How to create number sequences? Create Parameter table The parameter table will be used to store global parameters of the module. And will be used to hold the accessing method to the number sequence. Steps : 1. Create a now Table : <Module>Parameters 2. Add field key • Extends from ParametersKey • Visible = false, AllowEdit = false, AllowEditOnCreate = false 3. Create index name Key with AllowDuplicate = No 4. Set table properties • • • • • • TableContent = Default data ConfigurationKey CacheLookup = Found TableGroup = Parameter PrimaryKey = Key ClusterKey = Key
  6. 6. How to create number sequences? 5. Create find() method : find or create a record 6. Override delete() method : delete not allowed 7. Override update() method : in order to flush the cache.
  7. 7. How to create number sequences? Add value to NumberSeqModule Enumeration For each new module that handle the number sequence framework, you should add an Enum value to NumberSeqModule This value will be used to link number sequence to the module and to restrict displayed number sequence by module in Form. Set ConfigurationKey on the new value : if the CK is disabled the linked numberSequence will not be Displayed in form.
  8. 8. How to create number sequences? Create NumberSeqApplicationModule class This class allow to group and organize number sequence reference and sets default properties of a Sequence (continuous, max, manual…) Steps 1. Create class NumberSeqModule<Module> 2. Extends from NumberSeqApplicationModule 3. Override Method numberSeqModule() 4. Override method loadModule()
  9. 9. How to create number sequences? Create Form for module Parameters This Form will be used to display and edit module parameters table and number sequence reference. Steps: 1. Create a new form <Module>Parameters : template TableOfContent 2. In classDeclaration TmpIdRef NumberSeqScope NumberSeqApplicationModule boolean container 3. tmpIdRef; scope; numberSeqApplicationModule; runExecuteDirect; numberSequenceModules; Create method numberSeqPreInit() : called before the super() of form init method’s NB : A form can display NumberSequence for many module, fill numberSequenceModules container with all applied modules
  10. 10. How to create number sequences? 4. Add a Data Source with table “NumberSequenceReference” “NumberSequenceTable” as a Reference Data source. 5. 6. 7. Add a “TabNumberSeq” tab to the Form and add fields (copy CustParameters) AutoDeclare referenceSameAsLabel Create method numberSeqPostInit() : call after the super() of form’s init method and
  11. 11. How to create number sequences? 8. Override executeQuery() method NumberSequenceReference DS. This allow to apply a query to only show Number Sequences that • • • belong to modules we have defined in numberSeqPreInit(). Within the scope And have an active configurationKey 9. Add method removeFilter() to DS
  12. 12. How to create number sequences? Link EDT to module and setting default parameters for the sequence We have previously created class NumberSeqModule<Module>. We should add now all number sequence that belong to the module and set default parameters for each sequence. Sample :
  13. 13. How to create number sequences? Load numberSequenceReference Create a job and call NumberSeqApplicationModule::createReferences() You can use NumberSeqApplicationModule::createReferencesMulti() if you have created many modules and you want to load them with a single job Generate number sequences • Organization administration/Common/Number sequences/Number sequences • Click generate and follow wizard steps
  14. 14. How to create number sequences? You should now have see the result on the Parameter form you have created.
  15. 15. How to create number sequences? Create Accessing method For each data type specified in NumberSeqModule<MyModule>.loadModule(), you must create a static method on your parameter table. Create the <MyModule>Parameters::numRef<MyDataType>() method.
  16. 16. How to use number sequence in Form?
  17. 17. How to use number sequence in Form? AX provide the NumberSeqFormHandler Class that handle number sequences in Form. Steps : 1. Declare NumberSeqFormHandler in classDeclaration 2. Create method numberSeqFormHandler() method You should specify the data source and Field which will be automatically field by the Sequence number.
  18. 18. How to use number sequence in Form? 3. Override methods : create, write, delete mandatory, and linkActive, validateWrite Optional. Enjoy debug each method to lean what are they for?
  19. 19. How to use number sequence in Form? Continuous sequence! In order to avoid having gaps for continuous sequence you should add this code to the delete of the table. This allow to mark the Number as not used, so It will be used by the system at the next use of sequence number.
  20. 20. How to use number sequence in Form? Why should we use NumberSeqFormHandler? 1. It prevents having gaps in numbering 2. Add some interesting behaviors to Form • If the Sequence is not manual, it disallow editing the field to force the use of the sequence. • If the sequence is manual, it opens the field to modification in order to allow the user sets manually a value 3. Add many checks and validation rules
  21. 21. How to use number sequence in X++ ?
  22. 22. How to use number sequence in X++ ? The basic syntax for using number sequence in AX is : But this only work for non-continuous sequence. For Continuous number it will throw an exception.
  23. 23. How to use number sequence in X++ ? Continuous sequence handling For continuous sequences, Ax provide a simple mechanism to avoid having gaps in numbering : • Use the TTS level to decide whether sequence is consumed or not. • Use “_MakeDecisionLater” parameter, and manually code the used/abort of the sequence (developer decision). It is recommended to use the TTS level approach as it is more simple, and minimize the risk of forgetting some code by developer.
  24. 24. How to use number sequence in X++ ? Number Sequence Framework in action
  25. 25. How to use number sequence in X++ ? Use the TTS level Sample1: In this case, AX will automatically make the number as used on the call of ttscommit;
  26. 26. How to use number sequence in X++ ? Sample 2: In this case AX will automatically abort the use of Number as we have thrown an exception (line 15). A next call to the sequence will generate the same number, so no gap. PS : It is a trivial fact, that when we have a TTS within a try/Catch, AX call automatically a ttsabort one we have an exception  No need to call ttsabort.
  27. 27. How to use number sequence in X++ ? Use “makeDecisionLater” parameter In this scenario, it is up to the developer to decide when the number is used or aborted. When instantiating NumberSeq we should pass true as a second parameter: In line 14, the developer decide to mark the number as used : used() function.
  28. 28. How to use number sequence in X++ ? In this case the developer abort the use of the number : abort() function. so in the next call to the sequence, AX will generate the same number as previous and we will not have gaps.
  29. 29. How to use number sequence in X++ ?
  30. 30. How to use number sequence in X++ ? WARNING When using “makeDecisionLater”, you should make attention to call used/abort functions. Forgetting this may cause serious problem in the sequencing : We have seen that AX insert a record NumberSequenceList with status Active A manual cleanup will change the status of records to Free, so the numbers will be reused by AX in next call to numberSequence  we will get the same number on different records, and If field is primary key we will get DuplicateKey exception.
  31. 31. How to use number sequence in X++ ? NumberSeq::newGetNum() throws by default an error when there is a problem in the setup of the Sequence : • NumberSeqReference not set • Setup between reference an a sequence not done In same case this default behavior isn’t acceptable. The third parameter is used to force the method to only return a null object without throwing any exception. So the developer need next to implement some extra rules to manage the case of lack of setup.
  32. 32. Contact me Mohamed Amine HAMDAOUI Email Website Phone +212 (0) 6 36 12 50 02 Thanks for your time, and see you in the next Lab! Please don’t hesitate to contact me if you find any error on the document or if you have any questions.

×