query.load(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Loads an existing query as a query.Query object.

Use this method to load a query definition that was previously created using the SuiteAnalytics Workbook UI. After the query is loaded, you can modify the query definition (for example, by setting additional property values), join the query definition with other query types, and execute the query in the same way as queries that you create using query.create(options).

You can provide either the workbook ID or the dataset ID of the query definition to load. You can obtain these IDs in the SuiteAnalytics Workbook UI. For more information, see Navigating SuiteAnalytics Workbook.

This method loads only the table view in the specified workbook. However, a workbook can include no table views, or it can include multiple table views. This method throws an exception in each of these cases (see Errors). If a workbook includes multiple table views, you can use query.listTables(options) to determine the ID of a specific table view. You can use this ID to load the corresponding table view.

Important:

The N/query module lets you create and run queries using the SuiteAnalytics Workbook query engine. You can use the N/query module to load and delete existing queries, but you cannot save queries. You can save queries using the SuiteAnalytics Workbook interface. For more information, see Navigating SuiteAnalytics Workbook.

Returns

query.Query

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

5 units

Module

N/query Module

Sibling Module Members

N/query Module Members

Since

2018.2

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.id

string

required

The workbook ID or dataset ID of the query definition to load.

You can obtain these IDs in the SuiteAnalytics Workbook UI. For more information, see Navigating SuiteAnalytics Workbook.

Errors

Error Code

Thrown If

UNABLE_TO_LOAD_QUERY

A query with the specified ID cannot be loaded because the query does not exist or you do not have permission to load it.

WORKBOOK_MORE_TABLEVIEWS_ARE_ASSIGNED

More than one table view is included in the specified workbook or dataset.

WORKBOOK_NO_TABLEVIEW_IS_ASSIGNED

No table views are included in the specified workbook or dataset.

Note:

If the loaded query does not return a desired sorting order, you must use the Query.runPaged() method for default sorting or specify your custom sorting before script execution.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/query Module Script Samples.

            // Add additional code
...
var myLoadedQuery = query.load({ id: 'custworkbook237'
}); var mySalesRepJoin = myLoadedQuery.autoJoin({ fieldId: 'salesrep'
}); var results = myLoadedQuery.run();
...
// Add additional code 

          

Related Topics

N/query Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices