Creating Number sequence record through code

Hi Friends,

I want to create a new record in NumberSequenceDetails form through code.

I have all mandatory values like Number sequence code, name, format, number allocation details etc.

When I am creating from front end, there is no problem. It is getting saved properly.

But when I am creating through code, I needs to fill NumberSequenceScope and some std fields.

I don’t know how to achieve this. Any suggesstions ?

Thanks in advance.

Regards,

Faisal Raja J

What code are you writing for creating number sequence ??

Hi Lalit,

Thanks for the reply.

Actually I am requesting for code only. I needs to create the record in NumberSequenceDetails form through code but inserting a new record in NumberSequenceTable requires NumberSequenceScope recid to be filled. I don’t how to achieve this.

Some utility class may exist to get these values. I am in need of that insert logic.

Regards,

Faisal Raja J

Just find the right scope, get its RecId and assign it to NumberSequenceTable.NumberSequenceScope field. What’s the problem?

Depending on your exact requirements, you may also find NumberSequenceTable::autoCreate() useful.

Hi Martin,

Thanks for the reply.

Actually I don’t know exactly the remaining values to be filled. I tried the below code in job,

NumberSequenceTable ns;

NumberSequenceScope scope;

ExtendedTypeId _edt;

;

ns.clear();

ns.NumberSequence = ‘TTT’;

ns.Txt = ‘Test’;

ns.Format = ‘TST-########’;

ns.NumberSequenceScope = scope.RecId;

ns.Lowest = 1;

ns.Highest = 99999999;

ns.NextRec = 1;

ns.insert();

_edt = extendedTypeNum(LEV_Str20);

NumberSequenceTable::autoCreate(_edt);

When I tried the below code, it is throwing the following warning msg

"Reference for autogeneration of number sequence is not specified."

The last line of the above code autoCreate::() requires the NumberSeqScope parameter which is a class. I don’t know what to pass for that variable.

Regards,
Faisal Raja J

Hi Martin,

Thanks for the reply.

Actually I don’t know exactly the remaining values to be filled. I tried the below code in job,

NumberSequenceTable ns;

NumberSequenceScope scope;

ExtendedTypeId _edt;

;

ns.clear();

ns.NumberSequence = ‘TTT’;

ns.Txt = ‘Test’;

ns.Format = ‘TST-########’;

ns.NumberSequenceScope = scope.RecId;

ns.Lowest = 1;

ns.Highest = 99999999;

ns.NextRec = 1;

ns.insert();

_edt = extendedTypeNum(LEV_Str20);

NumberSequenceTable::autoCreate(_edt);

When I tried the above code, it is throwing the following warning msg

"Reference for autogeneration of number sequence is not specified."

The last line of the above code autoCreate::() requires the NumberSeqScope parameter which is a class. I don’t know what to pass for that variable.

Regards,
Faisal Raja J

Hi Martin,

Can you suggest me the required alteration in the above code ?

Regards,

Faisal Raja J

Hi Faisal,

You can refer below link

http://lalitoberoi.wordpress.com/2012/10/22/ax-2012-how-to-create-new-number-sequence/

After completion of all procedure you need to write below code if you need to create record through X++.

Below example based on project parameters.

NumberSeq numSeq;

numSeq = NumberSeq::newGetNum(projParameters::numRefProjInvoiceProjId(), true, true);
table1.fieldname = numSeq.num();

Best Regards,

JT

The problem is not in scope - it would be assigned automatically. The problem probably is that the data type doesn’t exist in NumberSequenceDatatype table. (The debugger would show you that.)

The EDT reference is normally created from the definition in a NumberSeqModule* class, although you should be able to create it also by NumberSeqDatatype class.

Hi Jagannath,

I am not asking about getting new number for the existing number sequence or creation of number sequence through the code.

I needs to create a new record in NumberSequenceDetails form through code.

Regards,

Faisal Raja J

Hi Martin,

I can able to create a new record in NumberSequenceDetails form through code. I have filled all the field values in NumberSequenceTable including Format.

But when I open the NumberSequenceDetails form all the values are coming except “Format” value though it is available in table. I couldn’t find the reason.

Any suggesstions pls?

Regards,

Faisal Raja J

Hi,

Can Any body tell me how to create a number sequence in ax 2012 based on Fiscal Calender’s,

like xxxxx2013 if the year is 2012 then my number seq should be xxxx2012…

Thanks in Advance …

I have found the solution and I posted it in my blog.

http://axcorner.blogspot.com/2013/12/create-number-sequence-record-through.html

Regards,

Faisal Raja J

Hello Faisal,

Good one dude .

Regards,

Kevin