InitValue Table method in ax 2012

Description:-

This method is called when a new record is created. It populates the record with initial values for the fields.The initValue method can be overridden on a form data source by right-clicking the Methods node under the data source, pointing to Override Method, and then clicking initValue.

The initvalue() is usually executed automatically on insert and it loads the default value.Here is the sample code to Generate Number sequence from table method in ax 2012.

public void initValue()
{
    str 60 _newCode;
    int max1;
    Table1 Table1;
    super();
    select firstOnly SrNo from Table1 order by RecId desc;
    if(!Table1.SrNo)
    {
        ttsBegin;
        _newCode=strRFix(int2str(1),6, "0");
        this.SrNo = _newCode;
        ttsCommit;
    }
    else
    {
        ttsBegin;
        max1=str2int(subStr(Table1.SrNo,1,6))+1;
        this.SrNo =strRFix(int2str(max1),6, "0");
        ttsCommit;
    }
}

Related Posts

Previous
Next Post »

Thanks for comments.....