Tuesday, 17 July 2012

Creating a new Number Sequence for an Existing Module in Ax2009, and Putting it to Use!

When I first learned how to create a Number Sequence in my Dynamics AX 2009 Development IV Class (80014) in February of 2010, I left with more confusion about the topic than it should have, and I dreaded coming back to work with the prospect of actually having to implement new Number Sequences. However, once I pulled together the precise steps from various books, online documents, and flat out trial-and-error, the task turned out to not be quite as bad as I had originally left the class thinking. I was however dumbfounded as to why no single source (that I was able to find) outlined the exact steps from creating a new Number Sequence to putting it to use in one clean tutorial. 

NOTE: Please bear with me in this tutorial; I am going to break naming convention best practices, so that my example is clearer.

The first thing you need to do is determine which module you want/need to create the new number sequence for. For this example, I am going create a new number sequence for the “Accounts Receivable” module. Then take the following steps:

Creating a new Number Sequence for the Accounts Receivable Module

1. Create your Extended Data Type that will be used in your table as your Number Sequence field. For this example we will create a string based Extended Data Typecalled edt_ComplaintId (with a Label property = “Complaint Report”)

2. Next, since we are using the “Accounts Receivable” module, we must modify the proper NumberSeqReference_XXXX Class. Accounts Receivable, actually maps to Customer (or Cust), so we need to make a modification to theNumberSeqReference_Customer class. 

We are only concerned with the loadModule() method, and will simply need to add the following code to it:

numRef.dataTypeId = typeId2ExtendedTypeId(typeid(edt_ComplaintId)); numRef.referenceHelp = "Unique key for the Complaint Report"; numRef.wizardContinuous = true;
numRef.wizardManual = NoYes::No;
numRef.wizardAllowChangeDown = NoYes::No;
numRef.wizardAllowChangeUp = NoYes::No;
numRef.wizardHighest = 999999;
3. After compiling and saving your changes, the next step is to use the Number Sequence Wizard to set it up. Click Basic > Setup > Number sequences >Number sequences to open the form where you can manage your Number Sequences.

4. Click on the “Wizard” button, which then should initialize the wizard. 

NOTE: If you receive an error at this point telling you “The application already has the required number sequences”, this means that you either did not add the definition to an established NumberSeqReference_XXXX Class' (in this example, the NumberSeqReference_Customer Class)loadModule() method, or you have already run the Wizard and set it up.
5. Once you arrive on the Wizard Welcome screen, click the Next > button.

6. On the following screen, verify that the Module is “Accounts receivable” and theReference is “Complaint Report” (which is the label of our Extended Data Type). TheNumber Sequence code is just an auto-generated value that you can leave as is (Remember this code, so that you can find it in your list of Number Sequences, because you are going to want to make a couple changes to it). Once you have verified the above, click the Next > button.

7. The next screen just gives you an overview, click the Finish button.

8. You should then see your Number Sequence in the list.

9. You will probably want to change the Format to something such as “CR-######”

10. At this point, your Number Sequence is ready for use!

Using the Number Sequence

1. Create a Table and name it tbl_Complaint

2. Add the edt_ComplaintId Extended Data Type as one of the fields (drag and drop the Extended Data Type directly into the fields of the Table) and name this field ComplaintId. 

3. Add the following Method to the tbl_Complaint:

static client server NumberSequenceReference numRefComplaintId()
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(edt_ComplaintId)));
4. Create a Form called frm_Complaint

5. Add the tbl_Complaint table to the form’s Data Sources, and name the Data Source ds_Complaint.

6. Add the following Methods to the Form:

public class FormRun extends ObjectRun
NumberSeqFormHandler numberSeqFormHandler;

NumberSeqFormHandler numberSeqFormHandler()

if (!numberSeqFormHandler)
numberSeqFormHandler = NumberSeqFormHandler::newForm(Tmt_CallReport::numRefComplaintId().NumberSequence, element, ds_Complaint.dataSource(), fieldnum(tbl_Complaint, ComplaintId));
return numberSeqFormHandler;
7. Add the following Methods to the ds_Complaint Data Source:

public void create(boolean _append = false)

public void delete()


public void write()

8. Your Number Sequence should now function!

Adding Find\Filter functionality on Display method

Override Context method of Form control which is using display method and provide code for filter. E.g I have done below for PhysicalInvent field of InventOnHandItem form. 

void context()

int selectedMenu;
real test;
formrun fr;
Args ag;
Itemname strtext;
querybuilddataSource qb1;
queryrun qr;
query q;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem('Find');
int b = menu.insertItem('Filter');
int c = menu.insertItem('Remove Filter');

selectedMenu = menu.draw();

switch (selectedMenu)
case -1:

case a:
ag = new args('SysformSearch');
fr = new formrun(ag);
strtext = fr.design().controlName('FindEdit').valueStr();
q = inventSum_Ds.query();
qb1 =q.dataSourceTable(tablenum(InventSum));

case b:

case c :



Friday, 6 July 2012

Number Sequence Creation in Ax 2012 For Existing Module

Here I want to design a form named FirstForm with DataSource FirstTable
I want to create sequence  like "AX00001---------AX99999".
Step 1
Create an EDT - String Type
So, I created an EDT named "AXSeqEDT" with label "AX Seq"

Drag into Table(FirstTable)àFields
Step 2
Now create a new Number Sequence
Path for creating num Sequence is
"Module:: Organization administration.......Common.........Number sequences......Number sequences"
Click on New(Number Sequence)

Now number Sequence form will be opened----That contains 4 sections.

Section 1.Identification.....Specify the NumberSeqCode and Name
Section 2.Scope Parameters... Select the Scope from the Dropdown
Section 3.Segments.... Add the constant and alphanumeric (by clicking the add button and selecting from drop down)
Section 4 .General.....Checkmark for continous and Specify the "smallest and largest and Next" Fields

Now Save Ur Settings
Step 3
Now add the Respective manual-code to class - NumberSeqModuleURMODULE
And Table - URMODULEParameters.
So I am creating number sequence based on HRM Module.....So iam using class NumberSeqModuleHRM andTable HRMParameters
Now go to AOT---Classes-NumberSeqModuleHRM---loadModule()

Add the code here...
Note::Here we can add the code seeing the existing implementation

The Added Code is::
/* setup discussion number sequence - it is global */


 Now Goto AOT---Tables---HRMParameters---methods-----click on new method

Add the code In the New method
Note::Here we can add the code seeing the existing implementation

The Added Code is
static client server NumberSequenceReference numRefAXSeqEDT()
    return NumberSeqReference::findReference(extendedTypeNum(AXSeqEDT));

Step 4
In order to add our newly created number sequence reference to our Module write the following Job and Execute it
Below job is important to run because without it your new number sequence will not be available to number sequence form under Parameters. This is the change in behavior from AX 2009 where all new number sequence loads while restarting the Dynamic AX. In AX 2012 all the number sequence created to system while installation, so restarting the AOS wont effect in loading the new number sequence, that is why it is important to run the job to load new number sequences.

The Code added in The Job is
static void jobName(Args _args)
    NumberSeqModuleHRM  NumberSeqModuleHRM = new NumberSeqModuleHRM();

Step 5
After executing the Above Job, our newly created number Sequence reference "AX Seq" will be added to HRM Module----Number sequence setup form
Lets Check it
Now click on Number Sequence and Identify the newly created Number Seq Reference

After Identifying the Number Sequence Reference ----Allot the Number Sequence Code to the Number Sequence Reference.....By selecting from the drop down list
Step 6
Now add the Code in Create method of Forms Datasource methods
Goto-AOT-Forms-FirstForm-Datasources-FirstTable-Methods-Override method(Create)
public void create(boolean _append = false)

    FirstTable.AXSeqEDT = NumberSeq::newGetNum(HRMParameters::numRefAXSeqEDT(),true).num();

Step 7
Now save all ur settings.....Now Open our form-FirstForm

Thanks & Regards