find and exists methods in x++
What is a find method?
-> It’s a method that selects and returns one record from the table that matches the unique index specified by the input parameters.
-> The last input variable in a find method must be a boolean variable usually called ‘_update’.
-> This variable has a default value of false.
-> When is set to true the caller object can update the record that is returned by the find method.
steps to follow:
1) Find the unique index of the table : Before continuing with creating the find method we need to find the unique index key of the table.
On the indexes tab we can see all indexes of the table. The unique index has Allow Duplicates properties set to No.
2) Create find method:
public static tablename find(WHSWorkId _workId,
boolean _forupdate = false) //find(EDT EDT Reference, boolean _forupdate=false)
{
WHSWorkTable workTable; tablename tablebuffer;
if (_workId) // EDT Reference
{
workTable.selectForUpdate(_forupdate);
select firstonly workTable
where workTable.WorkId == _workId;
}
return workTable;
}
Create exist method:
As with the find method, there should also exist an exists method in every table.
It basically works the same as the find method, except that on exist method we will return true if a record with the unique index
specified by the input parameter(s) is found or false if It’s not found.
Example:
public static boolean exist(WHSWorkId _workId)
{
return _workId &&
(select firstonly RecId from whsWorkTable
where whsWorkTable.WorkId == _workId).RecId != 0;
}
Comments
Post a Comment