file.found()
Description
file.found() indicates whether a record was found by the most recent file.getRecord(), file.positionTo(), file.positionAfter(), or file.delete() (with a search argument) call on a specific database file, in the same way as the RPG %FOUND(file) built-in function. It is called on the file instance created by pjs.defineTable(), using the internal file name (for example, productsp.found()).
Unlike pjs.found(), which reflects the most recent operation on any file, this method is specific to one file. The value is reset to false when the file is closed.
Syntax
file.found()Parameters
None.
Return Value
A Boolean value: true if a record was found, otherwise false.
Exception Handling
This method does not throw an error.
Examples
Example 1: Check the Result of a Keyed Read
The record is looked up by key and the program branches on whether it exists.
pjs.defineTable("productsp", { keyed: true, read: true });
productsp.getRecord(101);
if (productsp.found()) {
// Record fields are loaded and can be used here.
}
else {
// No record with key 101.
}Example 2: Check the Result of Positioning
After file.positionTo(), found() is true if any record with a key at or after the search argument exists, even when there is no exact match.
pjs.defineTable("productsp", { keyed: true, read: true });
productsp.positionTo(100);
if (productsp.found()) {
// There is at least one product with a key of 100 or higher.
productsp.fetchNext();
}RPG Equivalent
%FOUND(file_name)
Requirements
This API requires the Profound.js Connector module.