Find mode
Overview
Find Mode is a special mode in Servoy that allows users and developers to perform data searches using a high-level abstraction. When a foundset enters Find Mode, its data providers (normally used to read/write data) are instead used to enter search criteria. These criteria can be entered both through the user interface and programmatically.
Entering and Exiting Find Mode
A foundset enters Find Mode when its find
method is invoked. The find method returns a Boolean, indicating whether the foundset successfully entered Find Mode. It is good practice to use the find
method within an if
statement to avoid accidentally modifying the selected record. The foundset exits Find Mode when its search
method is executed, which modifies the foundset's SQL query to reflect the specified criteria and loads the matching records. The search
method returns an integer representing the number of records loaded by the find.
Example:
Resulting SQL Query:
Query Parameters:
Search Criteria with Logical AND
When multiple search criteria are entered for multiple data providers, they are concatenated with a SQL AND
operator.
Example:
Resulting SQL Query:
Query Parameters:
Multiple Find Records for Logical OR
Multiple record objects can be used to articulate search criteria in Find Mode, concatenating them with a SQL OR
operator.
Example:
Resulting SQL Query:
Query Parameters:
Finding Records Through a Relation
Find Mode can traverse the entire data model, allowing criteria to be entered in related foundsets.
Example:
Resulting SQL Query:
Finding Records within a Related Foundset
Related foundsets can also enter Find Mode and maintain the constraints of the relation.
Example:
Resulting SQL Query:
Special Operators
Servoy's Find Mode provides several special operators that, when used in combination, can articulate sophisticated search requirements. Operators and operands should be concatenated as strings.
Using Find Mode from Scripting without Using Special Operators or Spaces
You can use Find Mode with non-strings as well. For example, dates and numbers are not interpreted and will be used literally. Arrays can also be used when searching for multiple values.
Example:
Note:
When using a string for searching, it will be trimmed (except in the case of a CHAR
column, which is padded with spaces by the database). To ensure the argument is not interpreted, use a single-element array.
Example:
Find Mode and the User Interface
Find Mode can be entered in one action and searched in another, allowing users to manually enter values into fields to express search criteria. Once complete, the user can execute the search, and the form's foundset will show the results.
Example:
Find Mode blocks the execution of any methods normally invoked from the user interface. This ensures that unintended actions do not occur during a search. The @AllowToRunInFind
JSDocs tag allows the specified method to run while the form's foundset is in Find Mode.
Read-Only Fields
By default, read-only fields become editable in Find Mode, enabling users to enter search criteria. However, this behavior can be overridden using the Application API's setUIProperty
method.
Example:
Complex Searches
Servoy's Find Mode can easily satisfy complex search requirements. Any related foundset can be used to enter criteria, and any number of search records may be used in any foundset, combining any operators for each data provider.
Example:
Canceling Find Mode
Find Mode can be programmatically canceled by invoking the loadAllRecords
method of the foundset, reverting it to the query prior to entering Find Mode.
Last updated