Search This Blog

Wednesday 1 August 2012

Number Sequence in Dynamics AX 2012

Number Sequence:

The primary purpose of the number sequence framework is to provide unique, user-friendly identifiers while maintaining a continuous or non-continuous alphanumeric sequence.

Number Sequence should be the unique and user friendly.

Rec ID is also the unique but it is not user some times the dev requires the user friendly number.

The main core concepts are use in Number Sequence.

1. Segments

2. Scope.

Segment:
               Segment is basically the part of a Number Sequence that can be easily identifiable.

For example: A Student Enrolment Number.

BSCS:EP-086:171

Here BSCS is the degree type and department programe.

EP corresponds to evening programe.

08 is the year of admission

6 is the month.

and finally 171 is the roll numbe of  the student.

The above all segements combine to make a unique understandable Number Seqence.

Scope:
           Scope is basically the combination of segments used for a specific transaction or master data entity.

Example:Company + Fiscal Calender Period

value:DMO-Jan2011.

For Number Sequence we will use the Extended Data Types.
         Each Segment has its own EDT and an EDT using for sequence number can only be use for in
single module.
        We can not use same EDTs in more than one module if it is use as a Sequence Number.And EDT should be of String type.

Steps for Implementing Number Sequence:

Step 1: Make Extended Data Type of type String.Make its length above than 25 its depend on your choice but it should be the above than 25.I have nade that EDT as Enrolment Number.

Step 2:Now the point is in which module you are implementing the Nunber Seqence.I am Implementing in Human Resource Module so i will modifify the loadmodule method of
Class NumberSeqModuleHrm and write the following code.


datatype.parmDatatypeId(extendedtypenum(enrolmentnumber));
datatype.parmReferenceHelp(literalstr("enrolment number"));
datatype.parmReferenceLabel(literalstr("Enrolment number"));
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);

datatype.parmWizardIsChangeDownAllowed(NoYes::No);

datatype.parmWizardIsChangeUpAllowed(NoYes::No);

datatype.parmWizardHighest(999999);

datatype.parmSortField(12);

this.create(datatype);


In the above code I am basically defining the Extended Data Type that will be use for the Number Sequence.Help literal strings i.e Enrolment Number.Bascailly we use here labels.So when you Implementing put there Label.

ParmWizardContinious means Auto Incremented.There are two types Contonious and Manual.In Manual the user can manually edit or modifiy the Number Sequence. 

datatype.parmWizardIsChangeDownAllowed and datatype.parmWizardIsChangeUpAllowed is basically the option we can set is yes or no.Is use for example the user created 10 number sequences and than deleted 2 number sequence from the middle and when the next time the if the user is creating New Number Seqeunce than he can enter deleted values or not to remaing in the sorted order.


datatype.parmWizardHighest(999999) this showing the maximum value for the
EDT.


datatype.parmSortField(12) is basically the sorted value for the number of Number Sequences in a particular module. 
this.create(datatype); This line is basically calling the create method to create this Number Sequence.

Step 3:Now Create a  job and than write the following code.

NumberSequenceModuleSetup obj=new NumberSequenceModuleSetup();
 

obj.loadData();
 

info('Done');

The loadData method in above code is basically laoding data of all modules.In whicn our enrolement numer will also be load. 
When you run the job the Enrolment Number EDT will be load for the
Number Sequence as shown in the picture below.


 The form will open when you go to the Human Resource->Setup->Parameters->Human Resource Shared Parameters.


Step 4:Now made a numRefEnrolmentNumber method in the parameter table.Every module contains the parameter table.Parameter table is basically use to made the settings of the module.Now add the below method in the parameter table.The name of the parameter table of the Human Resource is HRMParameters.


static client server NumberSequenceReference numRefEnrolmentNumber()
{
    return NumberSeqReference::findReference(extendedTypeNum(enrolmentnumber));
}


The above method is basically returns the refrence of  the EDT Enrolement Number.

Step 5: Now I will create the student table to show the demo of the Number Sequence.Add two fields in the student table i,e Enrolment Number and Name of the student. These two fields should be extended from the EDT.

Step 6:Now add the following method to the in the student table to set the Number Sequence to Enrolement Number field.

public void SetEnrolmentNumber()
{
    NumberSeq num;
    NumberSequenceReference numberSequenceRefrence;
    numberSequenceRefrence=HRMParameters::numRefEnrolmentNumber();
    if(numberSequenceRefrence)
    {
        num=NumberSeq::newGetNum(numberSequenceRefrence);
        this.enrolmentnumber=num.num();
    }
}



Step 7:Now i will create the Simple List Details form to show the generated Number Sequence on that form.

Step 8:Now write the following method on that Student form that I have created above.


public NumberSeqFormHandler NumberSeqFormHandler()
{
    if(!numberSeqFormHandler)
    {
       NumberSeqFormHandler=NumberSeqFormHandler::newForm(HRMParameters::numRefEnrolmentNumber().NumberSequenceId,element,student_DS,fieldNum(student,enrolmentnumber));
    }

    return numberSeqFormHandler;
}


Step 9:Now add the Create,Delete and Write methods on the DataSource node of  the Student Form.

public void create(boolean _append = true)
{
    element.NumberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.NumberSeqFormHandler().formMethodDataSourceCreate();
}


public void delete()
{
    element.NumberSeqFormHandler().formMethodDataSourceDelete();
    super();


public void write()
{
    element.NumberSeqFormHandler().formMethodDataSourceWrite();
    super();
}


Step 10:Now the final thing you should create the number sequence format its Segments and Scope.Just go to the:

Organisation Administration->Common->Number Sequences->Number Sequence

and click new New Number Sequence in the action pane.




  Now set the Number Sequence code and Scope Parameter that can be shared  accross the companies or to the particular company  and than the Segments.





Now Close the Form and than go to the Human Resource->Setup->Parameters->Human Resource Shared Parameters and than select the Number Sequence Code against Your number Sequence Enrolment Number.



Now Run the form that we have created earlier to see the Number Sequences.You can see below in the image.



Thanks :)



















  




                 

No comments:

Post a Comment