Monday, April 27, 2015

Find and Exists Method in AX

Find :-

All tables should have at least one find method that selects and returns one record from the table that matches the unique index specified by the input parameters.

The last input parameter in a find method should be a Boolean variable called 'forupdate' or 'update' that is defaulted to false. When it is set to true, the caller object can update the record that is returned by the find method.

See the next example from the InventTable:

static InventTable find(ItemId itemId, boolean update = false --->to define how many primarykeys in table)
{
InventTable inventTable;
;
inventTable.selectForUpdate(update);
if (itemId)
{
select firstonly inventTable -->table name
index hint ItemIdx -->index name
where inventTable.ItemId == itemId;
}
return inventTable;
}

Exists :-

As with the find method, there should also exist an exists method.
It basically works the same as the find method, except that it just returns true if a record with the unique index specified by the input parameter(s) is found.

In the next example from the InventTable you can see that it returns true if the
input parameter has a value AND the select statement returns a value.

static boolean exist(ItemId itemId)
{
return itemId && (select RecId from inventTable
index hint ItemIdx
where inventTable.ItemId == itemId
).RecId != 0;
}

1 comment:

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// ...