Wednesday 12 August 2015

How to use generated number sequence at table level

How to use generated number sequence in table instead of form

     NOTE : Before starting, you must know how to generate a new number sequence. You can               check with the below link if you don't know already.

    Generating a new number sequence 
  • Very first thing you need to do is create a field in your table with the same data type as in your number sequence. Now go to the properties of newly created field and specify the EDT of number sequence.

     
  • Suppose, you've generated number sequence in HR module then create a new method in HRMParameters table. If you've generated number sequence in Customer module then create new method in CustParameters table. Similary if you've generated number sequence in any other module then check respective parameter table and create a new method there.

  • Write the following code in your method.

      Code:  
                    client server static NumberSequenceReference methodNamme()
                       {
                              return NumberSeqReference::findReference(extendedTypeNum(Your Number Sequence EDT name));
                        }

  • Now go to your table where you want to use number sequence and override initValue() method.
     Code:
                public void initValue()
                  {
                         NumberSeq numSeq;
                        super();
                        numSeq = NumberSeq::newGetNum(HRMParameters::numRefDemo());
                       this.Offer=numSeq.num();
                   }

  • Now open your table and check by creating new record.


  • Now you don't need to write code in form to generate number sequence.
Note: Generally in ax we don't use this concept because it's better to create new number sequence at form level where we can apply validation. But in exceptional case such as "inserting records from a class to table " where we can't create new sequence by using form so we have to use this concept.