Simple Find method

Hi, i'm going to show you how to write a simple find method on a table.

The purpose of writing a find method is to select the needed fields in a table, related with the data that you have in your hands. Find method is a "select" query actually that returns an entire table row or just which data you need from that table row.
You send the parameters with the called find method and you return the entire table or which field you want.

The below code is an example for a find method. This method must be written in your table then it can be called in every needed place like "ExampleTable::find()", and giving parameter in the method.
In the below code, we have an "exampleId" data in our hands that we can send as method parameter. In return of the method, we have the "exampleTable" entire data.

If needed, you can also update this table after finding the required data. (This is optional).


static exampleTable find(ExampleId _exId, boolean _forupdate = false)
{
    ExampleTable exampleTable;
;

    select firstonly exampleTable
        where exampleTable.exampleId == _exId;

    if(exampleTable && _forupdate)
        exampleTable.selectForUpdate(true);

    return exampleTable;
}

Comments

Popular posts from this blog

How to do barcode in SSRS (X++)

How to find Company Logo (X++)

How to find MainAccount with LedgerDimension (X++)