Monday, 12 January 2015

Generate number Sequence in ax 2012

Generate number Sequence



1)      Create a New EDT as RID



2)      Create a Table and Drag EDT in to this Table


3)      Write a code in lode module() under NumberSeqModuleProject Class in AOT




     datatype.parmDatatypeId(extendedTypeNum(RID));
     datatype.parmReferenceHelp(literalStr("R ID"));
     datatype.parmWizardIsManual(NoYes::No);
     datatype.parmWizardIsChangeDownAllowed(NoYes::No);
     datatype.parmWizardIsChangeUpAllowed(NoYes::No);
     datatype.parmWizardHighest(999999);
     datatype.parmSortField(56);
     datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
     this.create(datatype);

4)      Create an method  under Projparameters Table in AOT.



client server static NumberSequenceReference numRefRID()
{
     return NumberSeqReference::findReference(extendedTypeNum(RID));
}







5)      Create A job and Execute whether the Sequence is working or not




static void SRId(Args _args)
{
    NumberSeqModuleProject  NumberSeqModuleProject = new NumberSeqModuleProject();
    ;
    NumberSeqModuleProject.load();
}


6)      Then run the Wizard

Organisation Administration>>CommonForms>>Numbersequences>>Numbersequences>>Generate>>run the wizard.











7)      Create a Job to check the number sequence  is working or Not.



static void numberSRid(Args _args)
{
    NumberSeq  numberSeq;
    RID numRid;
    ;
    numberSeq = NumberSeq::newGetNum(ProjParameters::numRefRID());
    numRid = numberSeq.num();
    info(numRid);
}

8)      Run the above job once to get the Numbersequence Result in infolog.





















9)      Create a form to perform the above number sequence action in form level.

Add new Form with name of “RagSeq”



10)   Add Data Source of Existing “Table11”.
11)   In Design Drag the Fields which in DataSource Table.














12)   Create InitValue Method under table Method.



public void initValue()
{

     NumberSeq  numberSeq;
       ;
     super();
    numberSeq = NumberSeq::newGetNum(ProjParameters::numRefRID());
  this.RID =numberSeq.num();
}

13)   Add Number Sequence Reference Method



client server static NumberSequenceReference numRefRID()
{
     return NumberSeqReference::findReference(extendedTypeNum(RID));
}









14)   Save the Project and Open the Form to check the Result.



How to Read Table Properties through x++ code

Hi Friends,
The below piece of X++ code can be used to read properties of table fields.
To demonstrate, the below job will check the mandatory property of the fields of a table. This comes handy during technical analysis. It can be time consuming to check the property of each field manually.

The code uses DictTable and DictField classes to iterate through the table fields and it's properties. This can also be used to check other properties of the fields of a table.


static void checkProperties(Args _args)
{
    DictTable       dictTable;
    DictField       dictField;
    int             i, cnt;
   
    dictTable = new DictTable(tableNum(CustTable));
    cnt = dictTable.fieldCnt();
    for (i= 1; i<=cnt;i++)
    {
        dictField = new DictField(tableNum(CustTable),dictTable.fieldCnt2Id(i));
        if (dictField.mandatory())
        {
            info (strFmt("Field %1 is mandatory.",dictField.label()));
        }
    }
     
}
Similar to the way we have checked the property of field using dictField object in the above job, we can also read properties of any table using the dictTable object.

These classes are used at lot of places in standard AX code to iterate through table structures. Some common scenario are when we need to show list of table/fields in lookups.