query.runSuiteQL(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Runs an arbitrary SuiteQL query.

SuiteQL is a query language based on the SQL-92 revision of the SQL database query language. It provides advanced query capabilities you can use to access your NetSuite records and data.

You can specify the SuiteQL query as one of the following:

  • A string representation of the SuiteQL query

                            var results = query.runSuiteQL({ query: 'SELECT customer.entityid, customer.email FROM customer'
    }); 
    
                          
  • A query.SuiteQL object

                            // In this example, mySuiteQLCustomerQuery is an existing SuiteQL object
    var results = query.runSuiteQL(mySuiteQLCustomerQuery); 
    
                          
  • A JavaScript Object that contains a query property and, optionally, a params property

                            var results = query.runSuiteQL({ query: 'SELECT customer.entityid, customer.email FROM customer WHERE customer.isperson = ?', params: [true]
    }); 
    
                          
Note:

This method can return a maximum of 5000 results. If you need to return more results, use query.runSuiteQLPaged(options) instead.

For more information and examples of using SuiteQL in the N/query module, see SuiteQL in the N/query Module. For more information about SuiteQL in general, see SuiteQL.

Returns

query.ResultSet

Supported Script Types

Client and server scripts

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

Governance

10 units

Module

N/query Module

Sibling Module Members

N/query Module Members

Since

2020.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.query

string

required

The string representation of the SuiteQL query to run.

options.params

Array<string | number | boolean>

optional

The parameters to use in the SuiteQL query.

options.customScriptId

string

optional

A unique identifier used for potential performance issues in a query.

If your query produces performance issues, the custom script ID identifies where the update will need to occur.

This ID can also be used as a precaution to speed up performance fixes, if necessary.

Note:

The Script ID must be unique or the performance enhancements will affect each query with the same customScriptID.

Errors

Error Code

Thrown If

MISSING_REQD_ARGUMENT

The parameter is missing.

SSS_INVALID_TYPE_ARG

Types other than string, number, or boolean are included in the options.params array.

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 results = query.runSuiteQL({ query: 'SELECT customer.entityid, customer.email FROM customer WHERE customer.isperson = ?', params: [true], customScriptId: 'myCustomScriptId'
});
...
// Add additional code 

          

Related Topics

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

General Notices