I have a custom utility which uses a custom table in AX 2012 AOT, I want to have an identity field for my table and someone tell me I can use number sequences for this, and can map a number sequence to my table so it can get a new unique id at the time of row insert, when I try to generate number sequence it asks me AREA and module information, since i want this for my custom table and utility which is working outside the dynamics ax 2012 using .net business connector, I am unable to figure out what to input the wizard.
2 Answers
You have probably seen the method of using NumberSeqModule enum and adding a custom module enum value to it. Then you would normally create a class that extends the NumberSeqApplicationModule class and then load the numbersequences linked to the data types using number sequence references.
Though this is the 'best practice way', it is a bit of overkill for what you would want to do now. So here is what you can do:
You could just overwrite the insert method of the table you are using. And the you could use the newGetNumFromCode constructor on the NumberSeq class.
public static NumberSeq newGetNumFromCode(
NumberSequenceCode _numberSequenceCode,
NumberSeqScope _scope = NumberSeqScopeFactory::createDefaultScope(),
boolean _makeDecisionLater = false,
boolean _dontThrowOnMissingRefSetUp = false,
SysLastValue _nextNumSeq = null,
boolean _fillNextNumSeq = false)
{
return NumberSeq::newGetNumFromId(
NumberSequenceTable::findByNaturalKey(_numberSequenceCode, _scope.getId()).RecId,
_makeDecisionLater,
_dontThrowOnMissingRefSetUp,
_nextNumSeq,
_fillNextNumSeq);
}
So now to use this, you just have to create a new numbersequence within Dynamics Ax (Organization administration | Number Sequences | Number Sequences) and remember the number sequence code.
Then on the insert method of your table you can do the following: (the example is taken from the contact person table)
if (!this.ContactPersonId)
{
this.ContactPersonId = NumberSeq::newGetNum(CompanyInfo::numRefContactPersonId()).num();
}
That should make sure that when a record is inserted, you will also fill the ID.

- 894
- 1
- 5
- 16
-
thanks Kenny, I created a number sequence and override my insert method and used newGetNumFromCode method, I got duplicate numbers, then someone told me that I have to use continous number sequence and wrap the code in a transaction TTSBegin and TTSEnd. It worked. – alphaprolix Dec 17 '12 at 07:47
-
@Kenny Saelen: you used NumberSeq::newGetNum() in this example. I'm creating NumberSeq::newGetNumFromCode(), but it (at times, not always) throw an exception that "Number sequence does not exist". Any idea why is this so? I have generated number sequence using "new number sequence" in organization administration and not through code (using EDT stuff, loadModule() methods and all) or generate sequence wizard. – Bilal Saeed Dec 20 '13 at 09:07
This is how u you number sequence in normal way
custTable.xyz = NumberSeq::newGetNum(CompanyInfo::numrefContactId()).num();

- 11
- 1