Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Thursday, October 24, 2013

Creating & Using the find() methods in Dynamic AX 2012

Hi,
1. Create a table,
2. Use the 2 EDTs and make it one as index as unique by property AllowDuplicates : NO
3. Create a find method in the table using below code and patten

static TableName find(UsedEDT _UsedEDT ,
                       boolean          _forUpdate = false,
                       ConcurrencyModel _concurrencyModel = ConcurrencyModel::Auto)
{
    TableName  tableName ;

    if (_UsedEDT)
    {
        if (_forUpdate)
        {
            tableName .selectForUpdate  (_forUpdate);
            if (_concurrencyModel != ConcurrencyModel::Auto)
                tableName .concurrencyModel(_concurrencyModel);
        }
        tableName .selectLocked     (_forUpdate);

        select firstonly tableName
            index hint UsedEDTIndex
            where tableName.UsedEDT == _UsedEDT ;
    }

    return     tableName ;
}
/************************Using the find method **********************/
Using the display method with find() we can get that value by using below codes in the table.
display Name name()
{
    return TableName::find(this.UsedEDT).name();
}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. return TableName::find(this.UsedEDT).name();
    I got error in this line as syntax error.... Please clear that..

    ReplyDelete
  3. Let's say that you
    How to use find method in Modified method in another table to copy the value from TableName.Name to Table2.Name after modifying field Table2.Code?

    ReplyDelete

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...