microsoft dynamics ax2012 : number sequence framework, step by step
DESCRIPTION
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!TRANSCRIPT
Microsoft Dynamics® AX 2012
Number sequence framework
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++
how to create a new number sequence?
How to create number sequences?
How to create number sequences?
Create Parameter tableThe 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
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.
How to create number sequences?
Add value to NumberSeqModule EnumerationFor 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.
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…)
Steps1.Create class NumberSeqModule<Module>
2.Extends from NumberSeqApplicationModule
3.Override Method numberSeqModule()
4.Override method loadModule()
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 classDeclarationTmpIdRef tmpIdRef;NumberSeqScope scope;NumberSeqApplicationModule numberSeqApplicationModule;boolean runExecuteDirect;container numberSequenceModules;
3. 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
How to create number sequences?
4. Add a Data Source with table “NumberSequenceReference” and “NumberSequenceTable” as a Reference Data source.
5. Add a “TabNumberSeq” tab to the Form and add fields (copy CustParameters)
6. AutoDeclare referenceSameAsLabel
7. Create method numberSeqPostInit() : call after the super() of form’s init method
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
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 :
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
How to create number sequences?
You should now have see the result on the Parameter form you have created.
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.
How to use number sequence in Form?
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() methodYou should specify the data source and Field which will be automatically field by the Sequence number.
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?
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.
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
How to use number sequence in X++ ?
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.
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.
How to use number sequence in X++ ?
Number Sequence Framework in action
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;
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.
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.
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.
How to use number sequence in X++ ?
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.
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.
Contact me
Mohamed Amine HAMDAOUI
Website
Phone+212 (0) 6 36 12 50 02
Please don’t hesitate to contact me if you find any error on the document or if you have any questions.
Thanks for your time, and see you in the next Lab!