x++dynamics-ax-2012axdynamics-ax-2012-r2

Number sequence AX 2012


I have gone through msdn article, read whitepaper on number sequences and made number sequences a lot many times. But in this scenario I need some help.

Scenario is; I want to get next sequence number through x++ code using just number sequence code and no reference etc.

I have tried following (and many others but this is nearest solution) ;

static void myTestJob(Args _args)
{
    NumberSeq  num;

    num = NumberSeq::newGetNumFromCode('SAO-Y');

     info(num.num())  ;
}

It generates number sequence against some number sequence codes, but for other it throws error that;

"Number sequence does not exist."

I have tried many other options mentioned on many other blogs and tried to explore AX as well, but now need some assistance.

P.S. I'm not creating number sequence using x++ code but from front end (organization administration).


Solution

  • I am able to suppress the exception by using following;

    num = NumberSeq::newGetNumFromCode(<<someNumberSequenceCode>>, NumberSeqScopeFactory::createDefaultScope(), true, true);

    As, fourth optional parameter of NumberSeq::newGetNumFromCode(,,,true); says not to throw exception on missing reference.

    boolean _dontThrowOnMissingRefSetUp = false,

    As I said earlier, I have created number sequence from organization administration without writing any code (EDT, class, parameters table etc. stuff) so no reference was generated and I think I was getting exception due to this.