Monday, 5 October 2015

how number sequence is generated using format in ax 2012 - through code

job GetnextNumseq()
{
     NumberSeq num;
     num = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
    info(strfmt("%1",num.num));
}


Get Next number generated using format using X++ :
 int             purchreceiptcounter;
 PurchId         purchtblcounter;

//Find the Purch Id - from table.

 purchfind   =   purchTable.PurchId+ strRem(PurchParameters::find(false).LandedFreightTemplate,"#")+"*"; // Remove all '#' in format and add to Purch id.

// Get no. of Purchase orders created - PO1FFE*

            select count(RecId) from Purchtabletmp where Purchtabletmp.PurchId like purchfind;

            purchtblcounter=   int642int(Purchtabletmp .RecId); // Gets no.of records already inserted in table ...

            Purchtableins .PurchId   =   purchTable.PurchId+

// Which gets next numbersequence based on format

 NumberSeq::numInsertFormat(purchreceiptcounter+1,PurchParameters::find(false).Template);

//PurchParameters::find(false).Template) - Gets the format Value given - FFE##

Requirment :
PO1  ,

Next number sequence should be PO1FFE01 , if FFE## - Format

PO1FFE01
PO1FFE02
PO1FFE03
PO1FFE04
....

Suppose we have already PO1FFE02 in Purch table.  Now purchtbl counter - 2 , then Counter+1 value is passed to  "NumberSeq::numInsertFormat()" to get next number to insert in to table.


No comments:

Post a Comment