Showing posts with label number sequence. Show all posts
Showing posts with label number sequence. Show all posts

Tuesday, 22 December 2015

Creating Custom Number Sequences in Microsoft Dynamics AX 2012

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 to implement framework to generate custom number sequences.

Scenario

As part of this tutorial, a custom number sequence will be generated for the Customer Groups setup form (Accounts receivable àSetup à Customers à Customer groups)

Steps

  1. First create a new Extended Data Type (EDT). Open AOT àData Dictionary à Extended Data Types
  2. Right Click on Extended Data Types and create a new EDT NumSeqDemoCustGroupNum of type String
  3. Set the properties as shown below
  4.  
  5. Now go to AOT à Classes and open the NumberSeqModuleCustomer class by right clicking it and selecting View Code
  6.  
  7. In the loadModule method, add the following code after the last line of code
  8. //customer group number
    //define the EDT
    datatype.parmDatatypeId(extendedTypeNum(NumSeqDemoCustGroupNum));
    //define its default propertiesdatatype.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);
     
  9. Now, go to AOT à Jobs and create a new job loadNumSeqCustDemo
  10. Write the following code in the job and then run it
    static void loadNumSeqCustDemo(Args _args){
    //define the class variableNumberSeqModuleCustomer seqMod = new NumberSeqModuleCustomer();
    //load the number sequences that were not generatedseqMod.load();}
     
  11. Now, go to Organization administration à Common à Number sequences à Number sequences
  12. Click on Generate button in the New button group
  13. In the Setup number sequences wizard, Press Next
  14. In the Setup set different values for the number sequence like the format, highest value and lowest value
  15. Click Next
  16. In the last step, Click Finish to generate the number sequences
  17. The number sequence is generated and can be used on the Customer Groups form
  18. Open AOT à Data Dictionary à Tables à CustGroup
  19. Add a new String field and set the properties as follows
  20. Add the newly added field in the Overview field group
  21. Now go to Forms àCustGroup and restore the form. It will add the newly added field in the grid
  22. Write the following code on the Class declaration node
     NumberSeqFormHandler numberSeqFormHandler;
  23.  
  24. Create a new method on the form and write the following code
    NumberSeqFormHandler 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,CustGroup_DS,fieldnum(CustGroup,CustGroupNumber));}return numberSeqFormHandler;
    }
  25.  
  26. Override the close method of the form and write the following code
    public void close(){
    if (numberSeqFormHandler)
    {numberSeqFormHandler.formMethodClose();}
    super();}
  27.  
  28. Override the create method on the CustGroup data source and add the following code
    public void create(boolean _append = false){
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate(true);}
  29.  
  30. Override the write method on the CustGroup data source and add the following code
    public void write(){
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();}
  31.  
  32. Override the validateWrite method on the CustGroup data source and add the following code
    public boolean validateWrite(){
    boolean ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    return ret;}
  33.  
  34. Override the delete method on the CustGroup data source and add the following code
    public
    void delete()
    {
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();}
  35.  
  36. Override the linkActive method on the CustGroup data source and add the following code
    public
    void linkActive()
    {
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();}
  37.  
  38. Now go to Accounts receivable à Setup à Customers à Customer groups
  39. Create a new record. The number sequence is generated according to the format defined as shown below

Creating Custom Number Sequences in Microsoft Dynamics AX 2012

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 to implement framework to generate custom number sequences.

Scenario

As part of this tutorial, a custom number sequence will be generated for the Customer Groups setup form (Accounts receivable àSetup à Customers à Customer groups)

Steps

  1. First create a new Extended Data Type (EDT). Open AOT àData Dictionary à Extended Data Types
  2. Right Click on Extended Data Types and create a new EDT NumSeqDemoCustGroupNum of type String
  3. Set the properties as shown below
  4.  
  5. Now go to AOT à Classes and open the NumberSeqModuleCustomer class by right clicking it and selecting View Code
  6.  
  7. In the loadModule method, add the following code after the last line of code
  8. //customer group number
    //define the EDT
    datatype.parmDatatypeId(extendedTypeNum(NumSeqDemoCustGroupNum));
    //define its default propertiesdatatype.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);
     
  9. Now, go to AOT à Jobs and create a new job loadNumSeqCustDemo
  10. Write the following code in the job and then run it
    static void loadNumSeqCustDemo(Args _args){
    //define the class variableNumberSeqModuleCustomer seqMod = new NumberSeqModuleCustomer();
    //load the number sequences that were not generatedseqMod.load();}
     
  11. Now, go to Organization administration à Common à Number sequences à Number sequences
  12. Click on Generate button in the New button group
  13. In the Setup number sequences wizard, Press Next
  14. In the Setup set different values for the number sequence like the format, highest value and lowest value
  15. Click Next
  16. In the last step, Click Finish to generate the number sequences
  17. The number sequence is generated and can be used on the Customer Groups form
  18. Open AOT à Data Dictionary à Tables à CustGroup
  19. Add a new String field and set the properties as follows
  20. Add the newly added field in the Overview field group
  21. Now go to Forms àCustGroup and restore the form. It will add the newly added field in the grid
  22. Write the following code on the Class declaration node
     NumberSeqFormHandler numberSeqFormHandler;
  23.  
  24. Create a new method on the form and write the following code
    NumberSeqFormHandler 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,CustGroup_DS,fieldnum(CustGroup,CustGroupNumber));}return numberSeqFormHandler;
    }
  25.  
  26. Override the close method of the form and write the following code
    public void close(){
    if (numberSeqFormHandler)
    {numberSeqFormHandler.formMethodClose();}
    super();}
  27.  
  28. Override the create method on the CustGroup data source and add the following code
    public void create(boolean _append = false){
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate(true);}
  29.  
  30. Override the write method on the CustGroup data source and add the following code
    public void write(){
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();}
  31.  
  32. Override the validateWrite method on the CustGroup data source and add the following code
    public boolean validateWrite(){
    boolean ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    return ret;}
  33.  
  34. Override the delete method on the CustGroup data source and add the following code
    public
    void delete()
    {
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();}
  35.  
  36. Override the linkActive method on the CustGroup data source and add the following code
    public
    void linkActive()
    {
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();}
  37.  
  38. Now go to Accounts receivable à Setup à Customers à Customer groups
  39. Create a new record. The number sequence is generated according to the format defined as shown below

Thursday, 26 November 2015

Multiple (Auto + Manual) Number Sequences in AX 2009


Usecase
Some of the customers want to use multiple number sequence for single table that is not currently available in AX 2009.
i.e. In invent module to create different types of items one required to use different sequence, here  addon comes into picture.

Technical Section
Create new class “NumberSeqDialog” and add methods as listed below.
class NumberSeqDialog extends RunBase
{
    NumberSequenceCode      parentCode;
    NumberSequenceCode      selectedCode;
    DialogField             dialogFieldNumberSeq;
    Dialog                  dialog;
}
public Object dialog()
{
    ;
    dialog = super();
    dialog.caption("Select number sequance");
    dialog.allowUpdateOnSelectCtrl(true);

    dialogFieldNumberSeq = dialog.addField(TypeID(NumberSequenceCode),"Select Number Sequence: ");

    return dialog;
}

public void dialogPostRun(DialogRunbase _dialog)
{
    ;
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);
    super(_dialog);
}

Below method will give you answer  of populer question
“How to override Control’s event method?”
Also gives you an idea of
“How to create lookup field on Dialog?”
public void Fld1_1_lookup()
{
    Object control = dialog.formRun().controlCallingMethod();
    ;
    NumberSequenceTable::lookupNumberSequenceCode(control, this.parmParentCode());
}

public boolean getFromDialog()
{
    ;
    this.selectedNumberSeqCode(dialogFieldNumberSeq.value());
    return true;
}

Below to method say, if you don’t want to use “pack unpack” create me like this!!!
container pack()
{
    return connull();
}
boolean unpack(container _packedValues)
{
    return true;
}

NumberSequenceCode parmParentCode(NumberSequenceCode _parentCode = parentCode)
{
    parentCode = _parentCode;
    return parentCode;
}

NumberSequenceCode selectedNumberSeqCode(NumberSequenceCode _selectedCode = selectedCode)
{
    selectedCode = _selectedCode;
    return selectedCode;
}

Modify NumberSequenceTable table

Add below fields to NumberSequenceTable
 “NumberSequenceParent” to set parent Number sequence. EDT, which will refer to NumberSequenceCode.
“Search for parent” to NoYes type enum field.
So finally it will look like,



 Modify “NumberSeqFormHandler” class
Create instance of above class in “NumberSeqFormHandler” class.
Put below code in to newForm method

   if(NumberSequenceTable::find(_numberSequenceCode).SearchForParent)
    {
        numberSeqDialog = new NumberSeqDialog();
        numberSeqDialog.parmParentCode(_numberSequenceCode);
        if(numberSeqDialog.prompt())
        {
            _numberSequenceCode = numberSeqDialog.selectedNumberSeqCode();
        }
    }

So after adding above code your newForm method will look like,

static NumberSeqFormHandler newForm(NumberSequenceCode      _numberSequenceCode,
                                    ObjectRun                 _callerForm,
                                    FormDataSource          _formDataSource,
                                    fieldId                 _fieldIdNum,
                                    boolean                 _dontThrowOnMissingRefSetUp = false
                                   )
{
    NumberSeqFormHandler numberSeqFormHandler;
    NumberSeqDialog      numberSeqDialog;
    ;
    if (!_formDataSource || !_fieldIdNum)
        throw error(strfmt("@SYS70841",funcname()));

    //<Intech>
    if(NumberSequenceTable::find(_numberSequenceCode).SearchForParent)
    {
        numberSeqDialog = new NumberSeqDialog();
        numberSeqDialog.parmParentCode(_numberSequenceCode);
        if(numberSeqDialog.prompt())
        {
            _numberSequenceCode = numberSeqDialog.selectedNumberSeqCode();
        }
    }
    //</Intech>
    numberSeqFormHandler = NumberSeqFormHandler::construct(_formDataSource);

    numberSeqFormHandler.parmNumberSequenceCode(_numberSequenceCode);
    numberSeqFormHandler.parmFormDataSource(_formDataSource);
    numberSeqFormHandler.parmFieldIdNum(_fieldIdNum);
    numberSeqFormHandler.parmDontThrowOnMissingRefSetUp(_dontThrowOnMissingRefSetUp);
    return numberSeqFormHandler;
}
Direction of use

First of all you have to decide on which form you want to use multiple number sequence. Let’s say you have chosen InventTable and want to create items on item details page with different number sequence.
Next step is, go to Basic Setup> Number Sequences.  Find which number sequence is currently y in use to create new item. Let’s say its “Inv_60”, Remember this Number Sequence will be treat as BASE or say PARENT  number sequence.

Now, create different number sequences, as I have created “RM_61”, “FG_62” and “SFG_63” . Select  “Inv_60” against these create number sequences.
One more thing required to active this functionality, that is “Search for parent” option must be ticked on setup tab for “Inv_60” number sequence.

Have you done with all above steps?? If yes, you are ready to use this addon, Just go to Item details page. While creating new item it will search Three number sequences 61 to 63 created above.
and pop up with box shown below.




Select number sequence which you want to use for current item.

Furthermore, you want to give Number manually along with auto number sequence. Just select any of the above (61 to 63) as manually. You will  be having auto + manually number sequences!!!

Multiple (Auto + Manual) Number Sequences in AX 2009


Usecase
Some of the customers want to use multiple number sequence for single table that is not currently available in AX 2009.
i.e. In invent module to create different types of items one required to use different sequence, here  addon comes into picture.

Technical Section
Create new class “NumberSeqDialog” and add methods as listed below.
class NumberSeqDialog extends RunBase
{
    NumberSequenceCode      parentCode;
    NumberSequenceCode      selectedCode;
    DialogField             dialogFieldNumberSeq;
    Dialog                  dialog;
}
public Object dialog()
{
    ;
    dialog = super();
    dialog.caption("Select number sequance");
    dialog.allowUpdateOnSelectCtrl(true);

    dialogFieldNumberSeq = dialog.addField(TypeID(NumberSequenceCode),"Select Number Sequence: ");

    return dialog;
}

public void dialogPostRun(DialogRunbase _dialog)
{
    ;
    _dialog.formRun().controlMethodOverload(true);
    _dialog.formRun().controlMethodOverloadObject(this);
    super(_dialog);
}

Below method will give you answer  of populer question
“How to override Control’s event method?”
Also gives you an idea of
“How to create lookup field on Dialog?”
public void Fld1_1_lookup()
{
    Object control = dialog.formRun().controlCallingMethod();
    ;
    NumberSequenceTable::lookupNumberSequenceCode(control, this.parmParentCode());
}

public boolean getFromDialog()
{
    ;
    this.selectedNumberSeqCode(dialogFieldNumberSeq.value());
    return true;
}

Below to method say, if you don’t want to use “pack unpack” create me like this!!!
container pack()
{
    return connull();
}
boolean unpack(container _packedValues)
{
    return true;
}

NumberSequenceCode parmParentCode(NumberSequenceCode _parentCode = parentCode)
{
    parentCode = _parentCode;
    return parentCode;
}

NumberSequenceCode selectedNumberSeqCode(NumberSequenceCode _selectedCode = selectedCode)
{
    selectedCode = _selectedCode;
    return selectedCode;
}

Modify NumberSequenceTable table

Add below fields to NumberSequenceTable
 “NumberSequenceParent” to set parent Number sequence. EDT, which will refer to NumberSequenceCode.
“Search for parent” to NoYes type enum field.
So finally it will look like,



 Modify “NumberSeqFormHandler” class
Create instance of above class in “NumberSeqFormHandler” class.
Put below code in to newForm method

   if(NumberSequenceTable::find(_numberSequenceCode).SearchForParent)
    {
        numberSeqDialog = new NumberSeqDialog();
        numberSeqDialog.parmParentCode(_numberSequenceCode);
        if(numberSeqDialog.prompt())
        {
            _numberSequenceCode = numberSeqDialog.selectedNumberSeqCode();
        }
    }

So after adding above code your newForm method will look like,

static NumberSeqFormHandler newForm(NumberSequenceCode      _numberSequenceCode,
                                    ObjectRun                 _callerForm,
                                    FormDataSource          _formDataSource,
                                    fieldId                 _fieldIdNum,
                                    boolean                 _dontThrowOnMissingRefSetUp = false
                                   )
{
    NumberSeqFormHandler numberSeqFormHandler;
    NumberSeqDialog      numberSeqDialog;
    ;
    if (!_formDataSource || !_fieldIdNum)
        throw error(strfmt("@SYS70841",funcname()));

    //<Intech>
    if(NumberSequenceTable::find(_numberSequenceCode).SearchForParent)
    {
        numberSeqDialog = new NumberSeqDialog();
        numberSeqDialog.parmParentCode(_numberSequenceCode);
        if(numberSeqDialog.prompt())
        {
            _numberSequenceCode = numberSeqDialog.selectedNumberSeqCode();
        }
    }
    //</Intech>
    numberSeqFormHandler = NumberSeqFormHandler::construct(_formDataSource);

    numberSeqFormHandler.parmNumberSequenceCode(_numberSequenceCode);
    numberSeqFormHandler.parmFormDataSource(_formDataSource);
    numberSeqFormHandler.parmFieldIdNum(_fieldIdNum);
    numberSeqFormHandler.parmDontThrowOnMissingRefSetUp(_dontThrowOnMissingRefSetUp);
    return numberSeqFormHandler;
}
Direction of use

First of all you have to decide on which form you want to use multiple number sequence. Let’s say you have chosen InventTable and want to create items on item details page with different number sequence.
Next step is, go to Basic Setup> Number Sequences.  Find which number sequence is currently y in use to create new item. Let’s say its “Inv_60”, Remember this Number Sequence will be treat as BASE or say PARENT  number sequence.

Now, create different number sequences, as I have created “RM_61”, “FG_62” and “SFG_63” . Select  “Inv_60” against these create number sequences.
One more thing required to active this functionality, that is “Search for parent” option must be ticked on setup tab for “Inv_60” number sequence.

Have you done with all above steps?? If yes, you are ready to use this addon, Just go to Item details page. While creating new item it will search Three number sequences 61 to 63 created above.
and pop up with box shown below.




Select number sequence which you want to use for current item.

Furthermore, you want to give Number manually along with auto number sequence. Just select any of the above (61 to 63) as manually. You will  be having auto + manually number sequences!!!