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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s