Page History
...
Servoy's Find Mode provides several special operators that when used in combination can articulate the most 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 |
| ||
\ | Escape Character: Used to escape other string operators | Text |
| ||
now | Now: Matches records where the condition is right now, including time | Date |
| ||
today | Today: Matches records where the condition is any time today | Date |
|
Find Mode and the User Interface
The above examples deal with find mode in which find mode is entered, criteria are expressed and the search is run, all in a single action. The effect of the search is entirely up to the developer. However, find mode can also be entered in one action and searched in another action. In between, the user may manually enter values into fields to express the search criteria. They can then run the search action and a form's foundset will show the results of the search. Any of the above search criteria may be used.
Example In this example there is a method which can both enter find mode as well as run a search when in find mode. In between the two different invocations of this method, the user interface is ready to receive input from the user. When complete, the user may run the method again, this time the foundset will search for results.
Code Block |
---|
/**
* @AllowToRunInFind
*
* @properties={typeid:24,uuid:"088B830C-2A4F-483C-A135-5FA32A010AE9"}
*/
function doFind(){
if(foundset.isInFind()){ // if the foundset is already in find mode, run the search
foundset.search();
} else {
foundset.find(); // otherwise, enter find mode
}
}
|
Note |
---|
Find mode blocks the execution of any methods which are normally invoked from the user interface. This is a good thing as these methods may have unintended consequences when a form's foundset is in find mode. Notice the JSDocs tag @AllowToRunInFind in the comment block which precedes the method. This tag provides the metadata to let Servoy know that this method should be allowed to run while the form's foundset is in find mode. Without this exception, this method would be blocked from execution, and there would be no recourse to programmatically exit find mode. |
Read-Only Fields
By default, even read-only fields will become editable for the duration of the find mode. This is often useful, because while a data provider may not be available to edit, in find mode, it becomes a vehicle to enter a search criterion and should be editable to the user. However, in some cases it may be desired that read-only fields remain so for the duration of find mode as well. Servoy provides a UI property which may be set through the Application API using the method setUIProperty.
Example This example is identical to the above example with the exception, that for the duration of this find, the read-only property of fields is maintained. After a find, it is set back to the default so as not to interfere with other functionality throughout the rest of the application.
Code Block |
---|
/**
* @AllowToRunInFind
*
* @properties={typeid:24,uuid:"088B830C-2A4F-483C-A135-5FA32A010AE9"}
*/
function doFind(){
if(foundset.isInFind()){
foundset.search();
application.setUIProperty(APP_UI_PROPERTY.LEAVE_FIELDS_READONLY_IN_FIND_MODE, false) // reset to the default
} else {
application.setUIProperty(APP_UI_PROPERTY.LEAVE_FIELDS_READONLY_IN_FIND_MODE, true); // before entering find mode, enforce read-only fields
foundset.find();
}
}
|
Canceling Find Mode
Find mode can be programmatically cancelled by invoking the loadAllRecords method of the foundset. The foundset will revert to the query prior to entering find mode. Within the Smart Client the user can cancel Find mode by pressing Escape. This will trigger the loadAllRecords command of the Form to which the foundset is bound.
Complex Searches
Servoy's find mode can be used to easily satisfy even complex search requirements. Remember that any related foundset may be used to enter criteria and that any number of search records may be used in any foundset and any operators may be used in combination for every data provider.