AX 2012 - Create a custom number sequence

Today we will learn on how to create a custom number sequence and apply the same on a table

Create a table TEC_NumberSequence with following fields:
  •  Name
  • TEC_NumSeqID
Create an EDT named TEC_NumSeqID (string type)

Make a NumberSequence of following pattern “TEC00000”. And display on form when creating the new field number sequence should auto reflect. The form should be placed in Account Payable (vendor) Module.

         A)     Create the above mentioned table and EDT

Now you should find the class named NumberSeqModuleVendor (this is the class which opens number sequence module in AP module), then go to LoadModule method in that class and write the following at last:

// ID for NumSeq Table
    datatype.parmDatatypeId(extendedTypeNum(TEC_NumSeqID));
    datatype.parmReferenceHelp(literalStr("@TEC42"));
    datatype.parmWizardIsContinuous(true);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::No);
    datatype.parmWizardIsChangeUpAllowed(NoYes::No);
    datatype.parmSortField(1);
    datatype.parmWizardHighest(99999999);

    datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
    this.create(datatype);

Then go to Table node and find VendParameters table, go to methods node then add a new method and write the following:
    server static NumberSequenceReference TEC_NumberSequenceID()
      {
         return NumberSeqReference::findReference(extendedTypeNum(TEC_NumSeqID));  //Extended datatype
      }

Write the job to refresh and load the newly created EDT for NumberSequence
static void LoadNumberSequence(Args _args)
{
    NumberSeqModuleVendor  numberSeqModuleVendor = new NumberSeqModuleVendor();
    ;
    numberSeqModuleVendor.load();
}

Then go to AP content pane --> Setup --> Parameters --> Number Sequences Tab

Now here you will see the Extended Data type TEC_NumSeqID and an empty Sequence number code, right click the empty lookup and click Go to the main table Form.
Add a new number sequence code in the opened form and save it [for example]:
  • Number sequence code: TEC0001
  • Name: Unique number sequence ID
  • Smallest: 1
  • Largest: 99999
  • Next: 1
  • Format: TEC#####

Note: the format TEC##### has 5 #’s, so largest will also be five nine’s (99999).
Adding References is important, area – which module you want to attach your number sequence, reference – your EDT’s Label name.



Now create and Design your form



Now we want that Number Sequence in form level (Test Table):

Write below code in class declaration  :

public class FormRun extends ObjectRun
{
    NumberSeqFormHandler numberSeqFormHandler;
}

Add a new method in the existing form:-

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(VendParameters::TEC_NumberSequenceID().NumberSequenceId,
                                                            element,
                                                            TEC_NumberSequence_ds,
   fieldNum(TEC_NumberSequence, TEC_NumSeqID)
                             );
    }
    return numberSeqFormHandler;
}

Override the  Create(),Delete(),Write() , Validate Write(),Link Active() on the Data source methods node. Form>data source>table>Methods

Create () Method:

void create(boolean append = false,
            boolean extern = false
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(append);

    if (!extern)
    {
        element.numberSeqFormHandler().formMethodDataSourceCreate(true);
    }
}

Delete () Method:

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

Write () Method:

public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Validate Write () Method:

public boolean validateWrite()
{
    boolean         ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    if (ret)
    {
        TestTable.validateWrite(); //(your numbersequence table name)
    }
    return ret;
}

Link Active () Method:

public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}

Finally Override Close () method on form:

void close()
{
    if (numberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super();
}

Now test your form.



No comments:

Post a Comment