Interview Questions

Wednesday, March 26, 2014

Create Number Sequence for a new Module in AX 2012

Steps for creating number sequence for New Module: By Gulshan Kumar Gupta
*********************************************************************************
1- First of all, create a "Parameter" table in "Table" node of AOT (Like – “OfcAdminParameters”).

2- Create "Key" field in that table.

3- Create "Index" for "Key" field.

4- Create several methods in "Methods" node of "Parameter" table in AOT. (Like - Delete, Update, exist, and Find,  NumberSeqModule)
***********************************************************************************************    
Methods –

Delete =>
Void delete ()
{
    Throw error ("@SYS23721");
}

Update =>
Void update ()
{
    Super ();
    //just write flush Parameter table name
    Flush OfcAdminParameters;
}


Exist =>
Static Boolean exist ()
{
    Return (select firstonly RecId from OfcAdminParameters).RecId != 0;
}

Find=>
//AOSRunMode::CalledFrom
Static OfcAdminParameters find (Boolean _forupdate = false)
{
    OfcAdminParameters parameter;

    parameter.selectForUpdate(_forupdate);

    Select firstonly parameter
        Index Key
        Where parameter.Key == 0;

    If (!parameter && !parameter.isTmp())
    {
        Company::createParameter(parameter);
    }

    Return parameter;
}

NumberSeqModule=>
Static client server NumberSeqModule numberSeqModule ()
{
    Return NumberSeqModule::OfcMgmt;
}

// If you want to create another module then -
5- Now, add an element to "NumberSeqModule" base eNum.

*********************************************************************************
6- Create a new Number Sequence Class Named "NumberSeqModuleModuleName"

7- Add a method "NumberSeqModule" to that class.

Method’s for NumberSeqModuleModuleName class –
Class Declaration =>
public class NumberSeqModuleOfficeManagement extends NumberSeqApplicationModule
{

}

Number SeqModule =>
Public NumberSeqModule numberSeqModule ()
{
   Return NumberSeqModule::OfcMgmt;
}

*********************************************************************************

8- Create a "Form" to display the new “parameter table's data”.

9- In Class "NumberSeqModuleModuleName" add override method "load module".
    Coding  of Load Module =>
  Public void loadModule ()
  {
    NumberSeqDatatype datatype = NumberSeqDatatype::construct ();
    ;

    //Gulshan
    datatype.parmDatatypeId(extendedtypenum(CourierID));
    datatype.parmReferenceHelp(literalstr("@SYS32633"));
    datatype.parmWizardIsContinuous(true);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::No);
    datatype.parmWizardIsChangeUpAllowed(NoYes::No);
    datatype.parmWizardHighest(99999);
    datatype.parmSortField(1);

    this.create (datatype);
    }


10-To load "NumberSeqLoadModule" information for module, create “Job”.
Coding for Job =>
Public static void InstallOfficeManagement (Args _args)
{
    NumberSeqModuleOfficeManagement n = new NumberSeqModuleOfficeManagement ();
   // NumberSeqModuleFacilityManagement n = new NumberSeqModuleFacilityManagement ();

    n.loadModule ();
    Print ("Job Executed Successfully");
    Pause;
}


11-Now Setup "Number Sequence" just follows these steps;
    a) Go to CEU> Organization Administration
    b) Then Number Sequences > Number Sequences
    c) Click on "Number Sequence" in "New" tab.
    d) Fill the information in "Identification" tab.
    e) In "Scope parameters" tab select (Shred/Company)
    f) In "Segments" tab set the length of number sequence.
    g) Now in "General" setup click "continuous" option.
    h) Save and generate.
    i) Click "close"

12-Now add "NumRef" method in "parameter table" name “NumRefEDTname”.
Coding for NumRef Method =>
static client server NumberSequenceReference numRefCourierID()

{

    return NumberSeqReference::findReference(extendedTypeNum(CourierID));


}



13-In class declaration of a form add =>
 Public class FormRun extends ObjectRun
{
     NumberSeqFormHandler NumberSeqFormHandler;
}


14-Add "NumberSeqFormHandler" method to the form.
Coding for NumberSeqFormHandler Method =>
NumberSeqFormHandler NumberSeqFormHandler ()
{
    If (!numberSeqFormHandler)
    {
        NumberSeqFormHandler = numberseqformhandler::newForm(OfcAdminParameters::numrefCourierTransID().NumberSequenceId,element,Courier_Invoice_Table_1_ds,fieldNum(Courier_Invoice_Table, CourierTransID));
    }
    Return NumberSeqFormHandler;
}


15-Write "close" method in form methods node and "link active, Validate write, Write, Delete" methods on methods     node of data source of form.
Coding  for “Close” Method=>
void close()
{
    if (NumberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super();
}

Coding  for datasource method’s =>
LinkActive =>
public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}

ValidateWrite =>
public boolean validateWrite()
{
    boolean         ret;
    ret = super();

    ret = element.numberseqformhandler().formMethodDataSourceValidateWrite(ret) && ret;
    if (ret)
    {
        Courier_Invoice_Table_1.validateWrite();
    }
    return ret;
}

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

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

Create =>
public void create(boolean _append = false)

{

    ;

   super(_append);
    //In the below line we have to write datasource name.fieldname (very very important for number sequence)
   Courier_Invoice_Table_1.courierTransID = NumberSeq::newGetNum(OfcAdminParameters::numrefCourierTransID(),true).num();

    Courier_Invoice_Table_1.InvoiceNumber = NumberSeq::newGetNum(OfcAdminParameters::numrefInvoiceNumber(),true).num();

    Courier_Invoice_Table_1.VoucherNumber = NumberSeq::newGetNum(OfcAdminParameters::numrefVoucherNumber(),true).num();

}


No comments:

Post a Comment