CREATE NUMBER SEQUENCE
OVERVIEW
Number sequences are
unique identifiers that can be associated with a master record so that they can
be individually distinguished. They can be either formatted as alpha-numeric
strings or simply as numbers. Microsoft Dynamics AX 2012 provides an easy way to
implement framework to generate custom number sequences. To create custom
number sequence need to follow some steps:
STEPS
- First create a new Extended Data Type (EDT). Open AOT→ Data Dictionary → Extended Data Types
- Right Click on Extended Data Types and create a new EDT ‘MyNumSeq’ of type String
- Set the properties as shown below
- Now go to AOT → Classes and
open the NumberSeqModuleCustomer class by right clicking
it and selecting View Code
- In the loadModule method, add the following code after the last line of code
//define the EDT
datatype.parmDatatypeId(extendedTypeNum(MyNumSeq));//define its default properties
datatype.parmReferenceHelp(literalStr(“Unique number for customer group”));
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.parmSortField(27);
datatype.parmDatatypeId(extendedTypeNum(MyNumSeq));//define its default properties
datatype.parmReferenceHelp(literalStr(“Unique number for customer group”));
datatype.parmWizardIsContinuous(true);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.parmSortField(27);
//define its scope
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
·
Now, go to AOT → Jobs and create a new job loadMyNumSeq
Write the following code in the job and
then run it
static void loadMyNumSeq(Args _args)
{
//define the class variable
NumberSeqModuleCustomer numSeqMod = new NumberSeqModuleCustomer();
{
//define the class variable
NumberSeqModuleCustomer numSeqMod = new NumberSeqModuleCustomer();
//load the number
sequences that were not generated
numSeqMod.load();
}
numSeqMod.load();
}
- Now, go to System Administration → Organization administration → Common → Number
sequences → Number sequences
- Click on Number Sequence button in the New button group
- In New Record change value of tabs according to your requirement.
Identification → Name and Code of
Number Sequence
Scope parameter → Scope → company
→company → “Your company”
Scope parameter → Scope → company
→company → “Your company”
·
Set values of segment tab as shown in picture below:
- Set values of General tab
- Set values in Largest and continuous as shown in picture and press close button
- Now click on Generate button and wait for some time it will create new number sequence.
- In the Setup number sequences wizard, Press Next
- In the last step, Click Finish to
generate the number sequences
- Now check your generated number sequence by typing name of your number sequence in filter
- Now goto Account Receivable , expand setup and click on account receivable parameters
- Now click on Number Sequence (left below as visible in picture) , in reference column find mynumseq (EDT) and in number sequence code column find mynum (your number sequence code)
- Create a new table, if you already have a table where you want to use number sequence add a new string field and set properties as follows
- Create a new form, if you already have a form in which you want to use number sequence then simply add the table to form’s data source.
- Write the following code on the Class declaration node
NumberSeqFormHandler numberSeqFormHandler;
- Create a new method on the form and write the following code
NumberSeqFormHandler numberSeqFormHandler()
{
if (!numberSeqFormHandler)
{
{
if (!numberSeqFormHandler)
{
//create a reference of number sequence form handler class
specifying the EDT, Data source
name and the field of the table
numberSeqFormHandler =NumberSeqFormHandler::newForm(NumberSeqReference::findReference
(extendedtypenum(NumSeqDemoCustGroupNum)).NumberSequenceId, element,MyNumSeqTable_DS,fieldnum(MyNumSeqTable,MyNumSeq));
}
return numberSeqFormHandler;
}
(extendedtypenum(NumSeqDemoCustGroupNum)).NumberSequenceId, element,MyNumSeqTable_DS,fieldnum(MyNumSeqTable,MyNumSeq));
}
return numberSeqFormHandler;
}
- Override the close method of the form and write the following code
public void close()
{
if (numberSeqFormHandler)
{
numberSeqFormHandler.formMethodClose();
}
{
if (numberSeqFormHandler)
{
numberSeqFormHandler.formMethodClose();
}
super();
}
}
- Override the create method on the MyNumSeqTable data source and add the following code
public void create(boolean _append
= false)
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
super(_append);
element.numberSeqFormHandler().formMethodDataSourceCreate(true);
}
}
- Override the write method on the MyNumSeqTable data source and add the following code
public void write()
{
super();
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}
}
- Override the validateWrite method on the MyNumSeqTable data source and add the following code
public boolean validateWrite()
{
boolean ret;
{
boolean ret;
ret = super();
ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret)
&& ret;
return ret;
}
}
- Override the delete method on the MyNumSeqTable data source and add the following code
public
void delete()
{
void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}
}
- Override the linkActive method on the MyNumSeqTable data source and add the following code
public
void linkActive()
{
void linkActive()
{
element.numberSeqFormHandler().formMethodDataSourceLinkActive();
super();
}
}
- Now open form.
- The number in number sequence will be automatically created every time you create a new record in form.
Please Explain this , i am new in Ax2012.
ReplyDeletenumberSeqFormHandler =NumberSeqFormHandler::newForm(NumberSeqReference::findReference
(extendedtypenum(NumSeqDemoCustGroupNum)).NumberSequenceId, element,MyNumSeqTable_DS,fieldnum(MyNumSeqTable,MyNumSeq));
}
basically i am confuse
extendedtypenum(NumSeqDemoCustGroupNum)).NumberSequenceId, element,MyNumSeqTable_DS,fieldnum(MyNumSeqTable,MyNumSeq
if i under stand NumSeqDemoCustGroupNum= EDT name
this for MyNumSeqTable_DS = Table name with _DS only
and MyNumSeqTable this is that table
this is that column which is assosiated with EDT MyNumSeq
That helped, thanks a lot :)
DeleteGood content info :)
ReplyDeletehi
ReplyDelete