Number Sequences

AX 2012: Generate next number sequence in X++

Posted on Updated on

Often we do not need to generate the next number sequence manually in X++ since creating records by using forms the system automatically handles number sequence generation by invoking Number Sequence Framework.

However, sometimes we need to generate number sequences manually in X++. The following code helps you to do that:

static void numberSequence(Args _args)
{
    NumberSeq             numberSeq;
    SMAServiceObjectTable serviceObjectTable;

    numberSeq = NumberSeq::newGetNum(SMAParameters::numRefSMAServiceObjectId());

    serviceObjectTable.clear();
    serviceObjectTable.ServiceObjectId = numberSeq.num();
    serviceObjectTable.insert();

    numberSeq.used();
}

NumberSeq is the class in action here. Its static method newGetNum() takes NumberSequenceReference as an input parameter. All you need to do is to find the relevant number sequence reference in your case. Usually there are parm methods defined on Tables which give you the number sequence references.