Scripting example 1: The period case
If you want to query data within a period of time, you can for example enter a search condition in a DATE field:
>01-jan-2006 & <31-dec-2006
However, a more user-friendly way to let the end-user query data within a time period, is to define a VariableSetDataSource object with two variables that represents a period of time, with a from date and a to date.
In two additional text fields, the user can then enter these dates.
Suppose, the search group of an info page contains an S_BOOK_DATE field that is connected to a BOOK_DATE column of a RESERVATION table.
To use variables to query data within a period of time, set up the data structure and configure the userface behavior:
Setting up the data structure
-
Open the appropriate page from the catalog.
-
From the Controls tab page of the catalog, drag a VariableSetDataSource object to the Page object in the object tree.
-
For the new VariableSetDataSource1 object, set the Name property to: period.
-
Drag two Variable objects to the period VariableSetDataSource object.
-
For these two Variable objects, set the Name property to fromDate and toDate respectively.
-
For these two Variable objects, set the Prompt property to From Date and To Date respectively.
The top of the object tree now looks like this:
Configuring the interface behaviour
- In the SearchColumnGroup, insert two TextColumnControl objects, with properties:
-
Data Source Name: period.
-
Data Source Item: fromDate and toDate respectively.
-
Task Mode: Edit.
-
For the event listener of the existing Search button, insert a callClientScript action.
-
Make sure this action is executed before the executeQuery action, by adjusting the Seqno property.
-
For this action, set the Script property to:
let fromDate = $.udb('period').cols('fromDate').val();
let toDate = $.udb('period').cols('toDate').val();
let bookDate = '';
if (fromDate !== '') bookDate = `>${fromDate}`;
if (fromDate !== '' && toDate !== '') bookDate += '&';
if (toDate !== '') bookDate += `<${toDate}`;
$.udb('RESERVATION').searchCols('BOOK_DATE').val(bookDate);
: Leave the column control in Edit mode.
- Save your changes, and re-publish the changed web page.