Wednesday, April 21, 2010

Creating a new Number Sequence for an Existing Module, 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 Type called 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 the NumberSeqReference_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;
this.create(numRef);
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 “Wizardbutton, 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 the Reference is “Complaint Report” (which is the label of our Extended Data Type). The Number 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)
{
element.numberSeqFormHandler().formMethodDataSourceCreatePre();
super(_append);
element.numberSeqFormHandler().formMethodDataSourceCreate();
}


public void delete()
{
element.numberSeqFormHandler().formMethodDataSourceDelete();
super();
}


public void write()
{
super();
element.numberSeqFormHandler().formMethodDataSourceWrite();
}
8. Your Number Sequence should now function!

11 comments:

  1. Hello,
    I am working Dynamics 6.0 and in the Number Sequence Wizard I am unable to see other modules except for General Ledger.Actually I am unable to post a Free Text Invoice due to the Number Squence Issue...for which I wanted to check in the wizard and there I could'nt find the Accnts Receivable module...Is it possible to add any existing module into it?

    ReplyDelete
  2. Really it was very useful Lasley thank u so much for dis post expectin more lyk dis from u it was simple n easily understandable ...

    ReplyDelete
  3. Thanks for an excellent post.

    I'm surprised by something though. You have to go through the wizard to set it up. The process is not completely automated.

    Once it is setup in the DEV envronment, how do you move it to production? Do you have to go through the wizard in production as well?

    ReplyDelete
  4. Hi,
    we can use this code to any module with small changes.
    Thanks
    Ramesh

    ReplyDelete
  5. Tmt_CallReport -> tbl_Complaint ??

    ReplyDelete
  6. So far, this is the best Number Sequencing content I've found on the internet.

    Question, how well does Number Sequencing play with SQL Server's Auto Increment?

    In other words, if I create a new table in the AOT, can I use both or are they mutally exclusive?

    ReplyDelete
  7. Hi

    i am new to Ax environment and having confused about Number sequence , now i got some idea about this.Great post

    Thanks
    GK

    ReplyDelete
  8. Hi

    i am new to this and your blog helped me lot to understand number sequence.This was the most simple and easiest explaination for the beginner's i have ever read.

    Thanks
    Diptesh

    ReplyDelete
  9. hi,

    thank you, it was a very helpful article, but I am a bit confused, when I used it to create a number sequence for training courses, it gave me an error ( Tmt_CallReport ) so I changed it by (CompanyInfo) it worked perfectly but I dont know why !!! maybe you can help me...

    thanks...

    Ahmad

    ReplyDelete
  10. Thank u sir I think this is the most simple way to explain number sequence

    ReplyDelete
  11. thanks a lot sir for that info

    ReplyDelete