Thursday, December 5, 2013

Create number sequence record through code including format in Ax 2012

The below code can be used to create a new number sequence record and format can also be specified without opening the form.      

NumberSequenceTable   numberSeqTable;
NumberSequenceScope  numberSeqScope;
container                         segments;
str                                   annotatedFormat, format;
;

select  numberSeqScope
       where numberSeqScope.DataArea == 'QYS';

segments += [[0, 'QYS']];
segments += [[-1,'-']];
segments += [[-2,'######']];

annotatedFormat  = NumberSeq::createAnnotatedFormatFromSegments(segments);
format                  = NumberSeq::createAnnotatedFormatFromSegments(segments, false);

numberSeqTable.clear();
numberSeqTable.NumberSequence           = '111';
numberSeqTable.Txt                                 = 'Test';
numberSeqTable.AnnotatedFormat           = annotatedFormat;
numberSeqTable.NumberSequenceScope = numberSeqScope.RecId;
numberSeqTable.Format                           = format;
numberSeqTable.Highest                           = 999999;
numberSeqTable.Lowest                           = 1;
numberSeqTable.NextRec                         = 1;
numberSeqTable.insert();

2 comments: