Run an Arbitrary SuiteQL Query
The following sample constructs a SuiteQL query string, runs the query as a paged query, and iterates over the results.
Note:
This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
/**
* @NApiVersion 2.x
*/
require(['N/query'], function(query) {
var sql =
"SELECT " +
" scriptDeployment.primarykey, scriptexecutioncontextmap.executioncontext " +
" FROM " +
" scriptDeployment, scriptexecutioncontextmap " +
" WHERE " +
" scriptexecutioncontextmap.scriptrecord = scriptDeployment.primarykey " +
" AND " +
" scriptexecutioncontextmap.executioncontext IN ('WEBSTORE', 'WEBAPPLICATION')";
var resultIterator = query.runSuiteQLPaged({
query: sql,
pageSize: 10
}).iterator();
resultIterator.each(function(page) {
var pageIterator = page.value.data.iterator();
pageIterator.each(function(row) {
log.debug('ID: ' + row.value.getValue(0) + ', Context: ' + row.value.getValue(1));
return true;
});
return true;
});
});
Related Topics
- N/query Module Script Samples
- Create a Query for Customer Records and Run It as a Non-Paged Query
- Create a Query for Transaction Records and Run It as a Paged Query
- Convert a Query to a SuiteQL and Run It
- Create a Query for a Custom Field
- Create a Query Using a Specific Record Field
- SuiteScript 2.x Modules
- SuiteScript 2.x
- SuiteAnalytics Workbook Overview