8 Running a Query from Script
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:worksheetName');
// Run the query for non-primary Data Block in a Worksheet:
var q = runQuery('ws:global:worksheetName:tableName');
For Data Worksheets, qualify the name as 'ws:global:path' or 'ws:user_name:path' for global or user scope, respectively.
In either case, 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.
// Assign data in first column, first row to Text component:
Text1.value = q[1][0];
Query parameters (if any) can be passed as part of the runQuery call. For example, to pass the Viewsheet '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
Binding Data to a Chart in Script, for various approaches to binding data to a chart.
runQuery, for additional information on runQuery.
Accessing Worksheet Data, to access data in the underlying Worksheet.
Data Mashup, for information on creating Worksheet assets.
| << 7 Changing Images with Script | © 1996-2013 InetSoft Technology Corporation (v11.5) | Appendix VS: Viewsheet Object Reference >> |