selectRefRecord() method on table buffers.

The selectRefRecord() on table buffers can be used to retrieve the reference record accociated with a particular field. The underlying implementation of the method takes care of selecting the correct record based on the relation between the referenced field and the parent table.

Let us take an example.

Suppose we want to select the CustGroup associated with a SalesTable record.

The normal way someone will do that is,

SalesTable salesTable;
CustGroup custGroup;
;

select firstonly salesTable;
custGroup = CustGroup::find(salesTable.CustGroup);

print custGroup.CustGroup;
print custGroup.Name;


The same can be achieved using the selectRefRecord() method as well,


SalesTable salesTable;
CustGroup custGroup;
;

select firstonly salesTable;
custGroup = salesTable.selectRefRecord(fieldnum(SalesTable, CustGroup));

print custGroup.CustGroup;
print custGroup.Name;


Both the implementation has the same the same number of lines of code but selectRefRecord() comes in handy when the referenced table doesn't have a seperate find() method.

Comments

Popular posts from this blog

The field with ID '0' does not exist in table - Cause and resolution.

How to add empty ranges in query

SysQuery::findOrCreateRange() - A better way to create dynamic query ranges