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:

// Find all customers in the city of Berlin
if (foundset.find()) {   // Enter find mode
    city = 'Berlin';     // Assign a search criterion
    foundset.search();   // Execute the query and load the records
}

Resulting SQL Query:

Copy code
SELECT customerid FROM customers WHERE city = ? ORDER BY customerid ASC

Query Parameters:

['Berlin']

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:

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.

Operator
Description
Applicable Data Types
Example

||

OR: Used to implement a logical OR for two or more search conditions in the same data provider

Any

|

Format: Used to separate a value and an implied format.

Date

!

Not: Used to implement a logical NOT for a search condition.

Any

#

Sensitivity Modifier: Implies a case-insensitive search for text columns. Implies a match on entire day for date columns.

Text, Date

^

Is Null: Matches records where a column is null.

Any

^=

Is Null/Empty/Zero: Matches records where a column is null, empty string value or zero numeric value

Text, Numeric

<

Less than: Matches records where the column is less than the operand

Any

<=

Less than or equal to: Matches records where the column is less than or equals the operand

Any

>=

Greater than or equal to: Matches records where the column is greater than or equals the operand

Any

>

Greater than: Matches records where the column is greater than the operand

Any

...

Between: Matches records where the column is between (inclusive) the left and right operands.

Any

%

Wild Card String: Matches records based on matching characters and wild cards

Text

_

Wild Card Character: Matches records based on

Text

</code>

Escape Character: Used to escape other string operators

Text

now

Now: Matches records where the condition is right now, including time

today

Today: Matches records where the condition is any time today

Date

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

Was this helpful?