microsoft dynamics ax2012 : number sequence framework, step by step

32
Microsoft Dynamics ® AX 2012 Number sequence framework

Upload: hamdaoui-mohamed-amine

Post on 15-Jan-2015

4.668 views

Category:

Technology


6 download

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

Page 1: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

Microsoft Dynamics® AX 2012

Number sequence framework

Page 2: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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++

Page 3: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

how to create a new number sequence?

Page 4: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to create number sequences?

Page 5: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 6: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 7: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 8: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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()

Page 9: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 10: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 11: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 12: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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 :

Page 13: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 14: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to create number sequences?

You should now have see the result on the Parameter form you have created.

Page 15: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 16: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to use number sequence in Form?

Page 17: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 18: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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?

Page 19: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 20: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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

Page 21: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to use number sequence in X++ ?

Page 22: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 23: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 24: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to use number sequence in X++ ?

Number Sequence Framework in action

Page 25: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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;

Page 26: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 27: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 28: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 29: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

How to use number sequence in X++ ?

Page 30: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 31: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

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.

Page 32: Microsoft dynamics ax2012 : Number Sequence Framework, Step by Step

Contact me

Mohamed Amine HAMDAOUI

Email

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!