Friday, 23 June 2017

Number Sequence

1.Create Number Sequence----In Ax 2012

If we want to create Number Sequence, follow Below steps….

Step1: Create Edtà StuId(stringedit)

Step2: Create Table-à Class Table àin this Table Add Some Field and Then the Primary Field To extend Above Edt.
Exp: StudentIdàExtendsàStuId.

Step3: Create New Form and add Data Source Above Table (Class Table).


Step4: Based On Requirement generate number sequence On Class Table Form in studentID…
So we will select Suitable Class and Add Some Code on that class Load Method…

Example: NumberseqModuleCustomer (or) NumberseqModuleProject (or)NumberSeqModuleBank (or) NumberSeqModuleGeneral…etc

Here  I have taken NumberseqModuleCustomer àload Module()àAdd some code Here.


    datatype.parmDatatypeId(extendedTypeNum(Studentid));
    datatype.parmReferenceLabel(literalStr("Student Id"));
    datatype.parmReferenceHelp(literalStr("Unique Student number"));
    datatype.parmWizardIsContinuous(false);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::Yes);
    datatype.parmWizardIsChangeUpAllowed(NoYes::Yes);
    datatype.parmWizardLowest(1);
    datatype.parmWizardHighest(99999);
    datatype.parmIsGroupEnabled(NoYes::Yes);
    datatype.parmSortField(54);

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

Step5: Add Method in Parameter Table Like: CustParameters (or) Vend Parameters (or) Projparameters.

Here I have Taken Custparameters  table add Below code…

client server static NumberSequenceReference numRefStuid()
{
     return NumberSeqReference::findReference(extendedTypeNum(Studentid));
}

//This Method Assign the Edt to Parameters table.
Step6: Write the job and Run the Job about Generating Number sequence.

static void Na_loadNumSeqstuid(Args _args)
{
//define the class variable
   NumberSeqModuleCustomer seqMod = new NumberSeqModuleCustomer();

//load the number sequences that were not generated
    seqMod.load();
    info("Generated");
}


Step6: Run The Wizard…
Organization Administration >> CommonForms >> Numbersequences>>Numbersequences>> Generate >> run the wizard.


Step7: Now we have to Check Number Sequence Is Correctly working or not. write Job Below

.
static void Na_number(Args _args)
{
    NumberSeq       numberSeq;
    Studentid       num;

    ;
    numberSeq = NumberSeq::newGetNum(CustParameters::numRefStuid());
    num = numberSeq.num();
    info(num);
}


Step8: Now we want to apply Number Sequence in form Level....Apply Below Code in form Level.
























Step9: Now We declare NumberSeqFormhandler classes in form Declaration.

public class FormRun extends ObjectRun
{
     NumberSeqFormHandler       numberSeqFormHandler;
}





Step10: Add NumberSeqFormHandler()  Method in Form Methods.

NumberSeqFormHandler        numberSeqFormHandler()
{

    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(CustParameters::numRefStuid().NumberSequenceId,
                                                             element,
                                                             Na_ClassDetails_DS,
                                                             fieldNum(Na_ClassTable, StudentId)
                                                            );
    }
    return numberSeqFormHandler;
}



Step11: Add Close () method in Form Method.

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



Step12: Add Create () method in Form Data Source Methods.

 public void create(boolean _append = false)
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(_append);

    element.numberSeqFormHandler().formMethodDataSourceCreate(true);

}



Step13: Add Write () method in Form Data Source Methods.

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



Step14: Add Validate Write () method in Form Data Source Methods.

public boolean validateWrite()
{
    boolean ret;

    ret = super();

    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;

    return ret;
}



Step15: Add Delete () method in Form Data Source Methods.

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



Step16: Add link Active () method in Form Data Source Methods.

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



Important Classes:
1.NumberSeqDataType               -------> Class
2.NumberSeqModuleCustomer  ------>Class
3.NumberSeqFormHandler       -------->Class

Tables:
1.OurTable (class Table)             ------->Table
2.CustParameters                         -------> Table



My Number Sequence is Generated.












Set The Setup in Account Receivable in Account Receivable Parameters














 Set the Setup of Number Sequence Id



Table Method Calling Sequences in Ax -2012

         Table Method Calling Sequences in Ax -2012

When we arecreating a new record  CTrl+N
----> InitValue()
When we are Changed the data in a field.
àValidateFieldValue() à validateField() àModifiedFieldValue() àModifiedField().
When we are save the table after entering some data and close the table.
àvalidateWrite() à aosvalidateInsert() à Insert().
When we are Open the Table which will contain some data.
à  aosValidateRead ().
When we are Save the Record.
à ValidateDelete() à aosValidateInsert() à Insert().
When we are modifying the record.
àValidateDelete() à aosValidateUpdate() à Update().
When We are delete the Record.
àValidateDelete() à aosValidateDelete() à Delete().

Examples and Methods Working Progress.
I have taken Student Table and enter some Records.
When we are opening a Table Below Methods will be calling.

Open table: 1. PostLoad,2. aosValidateRead.




When we are Create New Record or CTrl+N.
Then below method will be Calling.
New Record:1. InitValue


When we are move to Next Field then below methods will be calling.


Move Record: validate Field Value, Validate Field, Get Extension, Modified field Value, preremoting, aosValidateInsert, insert, Preremoting, Modified.


When we are Modifying The record then below methods will be calling.


Modify Record: Validate Field Value, ValiadteField, get extension, modified Field Value, Preremoting, aosValidateInsert, Preremoting, Modified Field.




When we are Update the Record then below Method will be Calling.



Update Record: Validate Field value, Validate Field, Get Extension, Modified Field Value, Preremoting, aosValidateInsert, insert, Preremoting, Modified Field, Validate write, Preremoting, aosValidateUpdate, Update, Preremoting.























When we are delete the Record then below Methods will be calling.



Delete Record:  Validate Delete, Preremoting, aosValidateDelete, Delete, Preremoting.


























When we are save the record then below methods will be calling.


Save Record: Validate Write, Preremoting, aosValidateUpdate, Update, Preremoting.























Caption ():


























Help Field (): 

àRetrieves the help text of the control.
public str helpField(FieldId _fieldId)
{
    str     ret;
    str     name;

    ret = super(_fieldId);
    //info("Called helpField Method");
    name = this.helpField(1);
    return ret;
}

Caption ():

àGet and set the Caption property of a table.
public str caption()
{
    str ret;

    ret = super();
    info("Called caption Method");
    ret = strFmt("%1 %2",this.StudentId,this.StudentName);

    return ret;
}


Clear ():

àRemove all Rows from the table Buffer.
This. Clear ()
Tablebufffer.Clear();


Equal ():

àDetermines Whether the specified Object is Equal to the Current one.
static void Na_equal(Args _args)
{
    VendTable       vendTable;
    VendTable       v1,v2;

    v1 = vendTable::find("1003");
    v2 = vendTable::find("1003");
    info(strFmt("%1",v1.equal(v2)));

}
ReturnsàTrue  Or false.


Post Load ():

àIs Executed after Record Is Read.
it is used to read records from database and you can perform any custom logic by overriding this method on any table.

Executed when record loaded.
public void postLoad()
{
    super();

    if (this.Name == 'MEL')
        this.Value = 5;
}

Merge ():
àMerges the current table with the specified table.
static void merge(Args _args)
{
    Na_ClassTable       na_ClassTableDelete;
    Na_ClassTable       na_ClassTable;
    //ReasonTable reasonTableDelete;
    //ReasonTable reasonTable;

    ttsBegin;
        select firstOnly forUpdate na_ClassTableDelete
            where na_ClassTableDelete.Address == 'Guntur';
        select firstonly forupdate na_classtable
            where na_classtable.address == 'hyderabad';

    na_ClassTableDelete.merge(na_ClassTable);
    na_ClassTable.doUpdate();
    na_ClassTableDelete.doDelete();
    ttsCommit;
}



Using List Class and Merge.

static void Na_ListMerge(Args _args)
{
    List list1  = new List(Types::Integer);
    List list2  = new List(Types::Integer);
    List combinedList  = new List(Types::Integer);
    int  i;

    for(i=1; i<6; i++)
    {
        List1.addEnd(i);
    }
     for(i=6; i<11; i++)
    {
        List2.addEnd(i);
    }

    combinedList = List::merge(list1, list2);
    info(strFmt("%1",combinedList.toString()));
    //pause;
}


Preremoting ():
àIs Executed Before a Cross-tire call being about to Executed for the Table That Would Pack its state to the Other tier.



get Extension ():
àReturns the Table extension.


get SQL Statements ():
àit is used to Return record from the database.
                ReturnsàString;


get Field Value ():
àGets the Value of the Specified field from a table buffer.
                Returnsàany type;


ISFormDataSource ():
àIndicates Whether the Data Source is a Form.
                ReturnsàBoolean;


Get Presence Field Data ():
àRetrieves the presence info value from the specified field.
                ReturnsàFieldId—EDT;FieldValue—any type.


Default Field ():
àPopulates Default values in a Field in the table.


Default Row ():
àPopulates Default values in a Field in the table in the non-interactive case.


Write ():
à Updates a Record if it exists otherwise insert Record.


Wait ():
à The most common use for this method is to start an object that asks the user for some input and then call the wait method on that object, such as a form. The next line of code is not executed until the object has called the notify or notifyAll method.
When the wait method is called from a form, you do not have to call the notify methods manually because forms call the Object.notifyAllmethod when the user either closes the form or presses the Apply button.
.
Reread ():
à Current Record from the database. It should not use to refresh the form data.
                 Data if you have added/removed records. It's often used if you change some values in the current   record in some code, and commit them to the database using. update () on the table, instead of through the form data source. 


To String ():
à Returns a string that represents the current object.
static void Na_tostring(Args _args)
{
     Object obj = new Object();

    info(strFmt("%1", obj.toString()));
  
}
Table Access Right ():
à Returns the table access right.
è  Type- Access Right Enumeration.
   like –NoAccess,View,Edit,Add,correction,delete.(0,1,2,3,4,5).

Buf2Con () && Con2Buf ():

à Converts a record into a container. (or) Converts Table Buffer Record to container.
à Converts a container into a record. (or) Converts container to Table Buffer Record.

static void Na_buf2con(Args _args)
{
    Na_ClassTable    na_ClassTable;
    Na_ClassTable    na_ClassTable2;
    container       packedTable;  
   
    ttsBegin;  
    na_ClassTable.StudentId = "Stu_119";
    na_ClassTable.insert();
    info(na_ClassTable.StudentId);
    info(na_ClassTable2.StudentId);
    ttsCommit;
    // pack
    packedTable = buf2Con(na_ClassTable);
    // unpack in a different table buffer
    na_ClassTable2 = con2Buf(packedTable);
    info(na_ClassTable2.StudentId);
    if (na_ClassTable2.StudentId == na_ClassTable.StudentId)
    {
        info("Values are equal");      
        info(na_ClassTable.StudentId);
        info(na_ClassTable2.StudentId);
    }
}