Wednesday, March 21, 2012

Add new number sequence to existing AX module


To demonstrate this I have creted new form “Method table” which stores some of the characteristics of the items so I have added this Method table to Invent module.
Key for this table is “MethodId” & we are going to create number sequence for this table.

Look out the following steps to add number sequence for newly created form/table in existing module of AX 2009
1.   Create New EDT (Extened data type), i.e “MethodId” of type “str” size “20”.
2.   Find Number sequence class, in this case it is “NumberSeqReference_Inventory”.
3.   Find “LoadModule” method, add following code at the end of the method.






















4.  Create Following method to Form’s (The Form on which you have added data source) method.
NumberSeqFormHandler numberSeqFormHandler()
{
    if(!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(ItemMethodTable::numRefMethodId().NumberSequence,
        element,ItemMethodTable.dataSource(),fieldnum(ItemMethodTable,MethodId));
    }
    return numberSeqFormHandler;
}


5.  Add folloing code to specified methods on the Form where you have added created table.
-          In Write Method
After super() write, element.numberSeqFormHandler().formMethodDataSourceWrite();
-          In Create Method
Before super() write,
       element.numberSeqFormHandler().formMethodDataSourceCreatePre();
After Super write,
element.numberSeqFormHandler().formMethodDataSourceCreate();
-           In delete Method
Before super() write,
      element.numberSeqFormHandler().formMethodDataSourceDelete();
           6. Now, you are done with code part, to give final touch go to, basic> Setup> Number Sequence and run       Wizard. To show up your created Number sequece in List.

That’s it. Enjoy DAXing J


Multiple (Auto + Manual) Number Sequences in AX 2009 & AX 2012


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!!!

Any suggestions and questions are Welcomed.

Happy DAXing J