4.1.1 Running a Query from Script
If possible, use Style Studio to bind queries to elements. See Query Performance Considerations. Note: runQuery does not retrieve data from Data Models.
To run a query defined in the query registry (query.xml) or any available Data Worksheet, use the runQuery() command.
// Run a query:
var q = runQuery('total sales');
// Run the query for primary Data Block in a Worksheet:
var q = runQuery('ws:global:path/worksheetName');
// Run the query for primary Data Block in a user-scope Worksheet:
var q = runQuery('ws:user_name:path/worksheetName');
// Run the query for primary Data Block in a local report-scope Worksheet:
var q = runQuery('ws::path/worksheetName');
To run the query for a non-primary Data Block in a Worksheet, simply append the desired table name to the specified string. For example:
// Run the query for non-primary Data Block in a Worksheet:
var q = runQuery('ws:global:path/worksheetName:tableName');
// Run the query for non-primary Data Block in a local report-scope Worksheet:
var q = runQuery('ws::path/worksheetName:tableName');
In all cases, the runQuery() results are returned as a two-dimensional array, whose first row contains the column headers. You can access the query values using standard array indexing, and assign them to a table cell or text element:
// Assign first column of first data row to a table cell:
Table1.table[1][1] = q[1][0];
Query parameters (if any) can be passed as part of the runQuery() call. For example, to pass the report 'start_time' parameter to the query as 'start_time' and pass the current date/time as 'end_time':
var q = runQuery('total sales', [['start_time',
parameter['start_time'],['end_time', new Date()]]);
See Also
Independent Query, in Data Modeling, to design a new query.
Data Mashup, for information on creating Worksheet assets.
| << 4.1 Running a Query | © 1996-2013 InetSoft Technology Corporation (v11.4) | 4.1.2 Query Performance Considerations >> |