Wednesday, 18 February 2015

Generating number sequence in AX 2012

First of all to create a number sequence for a field in a table create a table with name Departments and having two fields deptId and deptName.
deptId is a new EDT created with name dept_Id and deptName with name EDT.

1) Goto organisation administration -> number sequences -> number sequences -> new number sequence -> 

Fill in the fields under identification fast tab and under segments click on add

Constant ---   DEPT
Constant ---   -
Alplanumeric --- ####

below that format now appears as DEPT-####

Remember that under general smallest is 1 and largest is 9999 as number of # specified under segments is 4 so write 9999(four 9's).

save it and generate the number sequence.

2) Classes -> NumberSequenceHRM -> loadmodule

    datatype.parmDatatypeId(extendedtypenum(Dept_Id));
    datatype.parmReferenceHelp(literalstr("@SYS852"));
    datatype.parmReferenceLabel(literalstr("@SYS386"));
    datatype.parmWizardIsContinuous(true);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::No);
    datatype.parmWizardIsChangeUpAllowed(NoYes::No);
    datatype.parmWizardHighest(9999);
    datatype.parmSortField(13);

    this.create(datatype);

you can copy and paste from the method but change the extendedtypenum, help, label, wizardhighest and sortfield number increase to next number.

3) DataDictionary -> Tables -> HRMParameters -> methods ->

create a new method numRefDeptId with the following code :

static client server NumberSequenceReference numRefDeptId()
{
    return NumberSeqReference::findReference(extendedTypeNum(Dept_Id));
}

4) In the newly created table Departments override the initValue and write the following code :

public void initValue()
{
    NumberSeq numberSeq;
    NumberSequenceReference numSeqRef;

    numSeqRef = InventParameters::numRefDeptId();
    numSeqRef = NumberSeqReference::findReference(extendedTypeNum(Dept_Id));

    super();

    numberSeq = NumberSeq::newGetNum(numSeqRef);
    this.deptId = numberSeq.num();
}

5) Create a job

static void numberSeqDeptId(Args _args)
{
    NumberSeqModuleHRM obj = new NumberSeqModuleHRM();
    obj.load();
}

save compile and run the job

6) Goto HumanResource -> Setup -> Parameters -> Human resources shared parameters

Under number sequences a new number sequence is created now with the label you mentioned now right click and view details. under general in use should be checked so that you can use this number sequence.

7) To check the number sequence goto table browser and ctrl-N 

DEPT-0001 comes under deptId


This is how a number sequence is generated and used .... :)




No comments:

Post a Comment