N/query Module
Use the N/query module to create and run queries using the SuiteAnalytics Workbook query process. For more information about SuiteAnalytics Workbook, see SuiteAnalytics Workbook Overview.
Using the query module, you can:
-
Use multilevel joins to create queries using field data from multiple record types.
-
Create conditions (filters) using AND, OR, and NOT logic, as well as formulas and relative dates.
-
Sort query results based on the values of multiple columns.
-
Load and delete existing saved queries that were created using the SuiteAnalytics Workbook interface.
-
View paged query results.
-
Use promises for asynchronous .
-
Convert query objects to SuiteQL queries and run arbitrary SuiteQL queries.
For more information about creating scripts using the N/query module, see the following help topics:
As you use the N/query module, keep the following considerations in mind:
-
The N/query module lets you create and run queries using the SuiteAnalytics Workbook query process. 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.
-
The N/query module uses a different data source than the N/search module. If you need to determine the ID of a record type or field (for example, to use as a query filter or result column), you must obtain this value from the Records Catalog, not the SuiteScript Records Browser. The Records Catalog lists every record type and field that is currently available in SuiteAnalytics Workbook and the N/query module. For more information, see Records Catalog Overview.
In This Help Topic
N/query Module Members
Member Type |
Name |
Return Type / Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Object |
Object |
Client and server scripts |
The field types (query result columns) that are displayed from the query results. Use Query.createColumn(options) or Component.createColumn(options) to create this object. |
|
Object |
Client and server scripts |
One component of the query definition. The query definition always contains at least one component that encapsulates the initial query type. Queries with joins contain multiple components that encapsulate the join relationships. The initial component (Query.root) is automatically created with the query definition (query.Query). Use Query.autoJoin(options) or Component.autoJoin(options) to create subsequent components. |
||
Object |
Client and server scripts |
A condition. A condition narrows the query results. Use Query.createCondition(options) or Component.createCondition(options) to create this object. |
||
Object |
Client and server scripts |
One page of the paged query results. |
||
Object |
Client and server scripts |
A set of paged query results. This object also contains information about the set of paged results it encapsulates. |
||
Object |
Client and server scripts |
A range of pages from the paged query results. |
||
Object |
Client and server scripts |
A period of time to use in query conditions. |
||
Object |
Client and server scripts |
A relative date to use in query conditions. |
||
Object |
Client and server scripts |
A single row of the query result set. |
||
Object |
Client and server scripts |
The set of results returned by the query. |
||
Object |
Client and server scripts |
The query definition. Use query.create(options) or query.load(options) to create this object. The creation of this object is the first step in creating a query with the N/query Module. |
||
Object |
Client and server scripts |
A sort that is placed on a particular query result column. Use Query.createSort(options) or Component.createSort(options) to create this object. |
||
Object |
Client and server scripts |
A SuiteQL query. Use Query.toSuiteQL() to create this object. |
||
Method |
Client and server scripts |
Creates the query definition. The of this method is the first step in creating a query with the N/query Module. |
||
Client and server scripts |
Creates a query.Period object that represents a period of time. |
|||
Client and server scripts |
Creates a query.RelativeDate object that represents a date relative to the current date. |
|||
void |
Client and server scripts |
Deletes an existing query that was created using the SuiteAnalytics Workbook UI. The deleted query is no longer available and cannot be modified or executed. |
||
<Object> |
Client and server scripts |
Lists the table view objects that are included in a workbook in SuiteAnalytics Workbook. |
||
Client and server scripts |
Loads an existing query that was created using the SuiteAnalytics Workbook UI. The loaded query can be modified (for example, by setting additional property values), joined with other query types, and executed in the same way as queries created using query.create(options). |
|||
Client and server scripts |
Asynchronously loads an existing query that was created using the SuiteAnalytics Workbook UI. |
|||
Client and server scripts |
Runs an arbitrary SuiteQL query. |
|||
Client and server scripts |
Asynchronously runs an arbitrary SuiteQL query. |
|||
Client and server scripts |
Runs an arbitrary SuiteQL query as a paged query. |
|||
Client and server scripts |
Asynchronously runs an arbitrary query as a paged query. |
|||
Enum |
enum |
Client and server scripts |
Holds the string values for aggregate functions supported with the N/query Module. This enum is used to pass the aggregate function argument to Component.createColumn(options), Component.createCondition(options), Query.createColumn(options), and Query.createCondition(options). |
|
enum |
Client and server scripts |
Holds the string values for supported date codes in relative dates. This enum is used to pass the date ID argument to query.createRelativeDate(options). |
||
enum |
Client and server scripts |
Holds the string values for the field context to use when creating a column. This enum is used to pass the context argument to Query.createColumn(options) and Component.createColumn(options). |
||
enum |
Client and server scripts |
Holds the string values for operators supported with the N/query Module. This enum is used to pass the operator argument to Query.createCondition(options) and Component.createCondition(options). |
||
enum |
Client and server scripts |
Holds the string values for adjustment types for a period. This enum is used to pass the adjustment argument to query.createPeriod(options). |
||
enum |
Client and server scripts |
Holds the string values for period codes for a period. This enum is used to pass the code argument to query.createPeriod(options). |
||
enum |
Client and server scripts |
Holds the string values for period types for a period. This enum is used to pass the type argument to query.createPeriod(options). |
||
enum |
Client and server scripts |
Holds query.RelativeDate object values for supported date ranges in relative dates. This enum is used to pass the values argument to Query.createCondition(options) and Component.createCondition(options). |
||
enum |
Client and server scripts |
Holds the string values for the formula return types supported with the N/query Module. This enum is used to pass the formula return type argument to Query.createColumn(options), Component.createColumn(options), Query.createCondition(options), and Component.createCondition(options). |
||
enum |
Client and server scripts |
Holds the string values for sort locales supported with the N/query Module. This enum is used to pass the sort locale argument to Query.createSort(options) and Component.createSort(options). |
||
enum |
Client and server scripts |
Holds the string values for supported query types used in the query definition. This enum is used to pass the initial query type argument to query.create(options). |
Column Object Members
The following members are available for a query.Column object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
string (read-only) |
Client and server scripts |
An aggregate function that is performed on the query result column. An aggregate function performs a calculation on the column values and returns a single value. |
|
string (read-only) |
Client and server scripts |
An alias for this column. An alias is an alternate name for a column, and the alias is used in mapped results. |
||
query.Component (read-only) |
Client and server scripts |
A reference to the query.Component object to which this query result column belongs. |
||
Object (read-only) |
Client and server scripts |
The field context for values in the query result column. The field context determines how field values are displayed in the column. |
||
string (read-only) |
Client and server scripts |
The name of the query result column. This property and the Column.formula property cannot be set at the same time. |
||
string (read-only) |
Client and server scripts |
The formula used to create the query result column. This property and the Column.fieldId property cannot be set at the same time. |
||
(read-only) |
Client and server scripts |
Whether the query results are grouped by this query result column. |
||
string (read-only) |
Client and server scripts |
The label for the column. |
||
string (read-only) |
Client and server scripts |
The return type of the formula used to create the query result column. |
Component Object Members
The following members are available for a query.Component object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Client and server scripts |
Creates a join relationship. After you create the initial query definition, use Query.autoJoin(options) to create your first join. Then use this method to create each subsequent join. This method selects the correct join type automatically based on the record types that are being joined. |
||
Client and server scripts |
Creates a query result column based on the component. Use this method to create columns based on the join relationships created with Query.autoJoin(options) and Component.autoJoin(options). |
|||
Client and server scripts |
Creates a condition (filter column) based on the component. Use this method to create conditions based on the join relationships created with Query.autoJoin(options) and Component.autoJoin(options). |
|||
Client and server scripts |
Creates a sort based on the component. Use this method to create sorts based on the join relationships created with Query.autoJoin(options) and Component.autoJoin(options). |
|||
Client and server scripts |
Creates a join relationship. This method is an alias to Component.autoJoin(options). After you create the initial query definition, use Query.autoJoin(options) to create your first join. Then use this method, or Component.autoJoin(options), to create each subsequent join. |
|||
Client and server scripts |
Creates an explicit directional join relationship from another component to this component (an inverse join). This method sets the Component.source property on the returned query.Component object. After you create the initial query definition, use this method to create explicit directional joins from other components to this component. |
|||
Client and server scripts |
Creates an explicit directional join relationship to another component from this component (a join). You can use this method to specify the target of the join when a field can join multiple query types. This method sets the Component.target property on the returned query.Component object. After you create the initial query definition, use this method to create explicit directional joins to other components from this component. |
|||
Property |
Object (read-only) |
Client and server scripts |
The child components of the component. This property holds an object of key-value pairs. Each key is the name of a child component. Each value is the corresponding child query.Component object. |
|
string (read-only) |
Client and server scripts |
The parent query.Component object of the component. |
||
string (read-only) |
Client and server scripts |
The source query type of the component. The value of this property is set when Component.joinFrom(options) is called to perform an explicit directional join from another component. |
||
string (read-only) |
Client and server scripts |
The target query type of the component. The value of this property is set when Component.joinTo(options) is called to perform an explicit directional join to another component. |
||
string (read-only) |
Client and server scripts |
The query type of the component. |
Condition Object Members
The following members are available for a query.Condition object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
string (read-only) |
Client and server scripts |
An aggregate function that is performed on the condition. An aggregate function performs a calculation on the condition values and returns a single value. |
|
query.Condition[] (read-only) |
Client and server scripts |
An of child conditions used to create the parent condition. |
||
query.Component (read-only) |
Client and server scripts |
A reference to the query.Component object to which this condition belongs. |
||
string (read-only) |
Client and server scripts |
The name of the field that is used in the condition. |
||
string (read-only) |
Client and server scripts |
The formula used to create the condition. |
||
string (read-only) |
Client and server scripts |
The name of the operator used to create the condition. |
||
string (read-only) |
Client and server scripts |
The return type of the formula used to create the condition. |
||
string | number | | <string | number | > (read-only) |
Client and server scripts |
An of values used by an operator to create the condition. |
Page Object Members
The following members are available for a query.Page object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
query.ResultSet (read-only) |
Client and server scripts |
The query results contained in this page. |
|
(read-only) |
Client and server scripts |
Whether this page is the first of the paged query results. |
||
(read-only) |
Client and server scripts |
Whether this page is the last of the paged query results. |
||
query.PagedData (read-only) |
Client and server scripts |
The set of paged query results that this page is from. |
||
query.PageRange (read-only) |
Client and server scripts |
The range of query results for this page. |
PagedData Object Members
The following members are available for a query.PagedData object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Iterator object |
Client and server scripts |
Standard SuiteScript 2.0 object for iterating through results. |
|
Client and server scripts |
Retrieves a page in the set of pages included in the |
|||
Client and server scripts |
Asynchronously retrieves a page in the set of pages included in the |
|||
Property |
number (read-only) |
Client and server scripts |
The total number of paged query results. |
|
Client and server scripts |
An of page ranges for the set of paged query results. |
|||
number (read-only) |
Client and server scripts |
The number of query result rows per page. |
PageRange Object Members
The following members are available for a query.PageRange object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
number (read-only) |
Client and server scripts |
The index for this page range. |
|
number (read-only) |
Client and server scripts |
The number of query result rows in this page range. |
Period Object Members
The following members are available for a query.Period object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
string (read-only) |
Client and server scripts |
The adjustment of the period. This property uses values from the query.PeriodAdjustment enum. |
|
string (read-only) |
Client and server scripts |
The code of the period. This property uses values from the query.PeriodCode enum. |
||
string (read-only) |
Client and server scripts |
The type of the period. This property uses values from the query.PeriodType enum. |
Query Object Members
The following members are available for a query.Query object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Client and server scripts |
Creates a new condition (a query.Condition object) that corresponds to a logical conjunction (AND) of the arguments passed to the method. The arguments must be one or more query.Condition objects. |
||
Client and server scripts |
Creates a join relationship. After you create the initial query definition, use this method to create your first join or subsequent joins from the root component of the query. This method selects the correct join type automatically based on the record types that are being joined. |
|||
Client and server scripts |
Creates a query result column based on the query.Query object. Use this method to create columns on the initial query definition created with query.create(options). |
|||
Client and server scripts |
Creates a condition (filter column) based on the query.Query object. Use this method to create conditions on the initial query definition created with query.create(options). |
|||
Client and server scripts |
Creates a sort based on the query.Query object. The query.Sort object describes a sort that is placed on a particular query result column or condition. |
|||
Client and server scripts |
Creates a join relationship. This method is an alias to Query.autoJoin(options). After you create the initial query definition, use this method, or Query.autoJoin(options), to create your first join. |
|||
Client and server scripts |
Creates an explicit directional join relationship from another component to the root component of the search definition (an inverse join). This method sets the Component.source property on the returned query.Component object. After you create the initial query definition, use this method to create your first join as an explicit directional join from another component to this component. |
|||
Client and server scripts |
Creates an explicit directional join relationship to another component from this component (a forward join). You can use this method to specify the target of the join when a field can join multiple query types. This method sets the Component.target property on the returned query.Component object. After you create the initial query definition, use this method to create your first join as an explicit directional join to another component from this component. |
|||
Client and server scripts |
Creates a new condition (a query.Condition object) that corresponds to a logical negation (NOT) of the argument passed to the method. The argument must be a query.Condition object. |
|||
Client and server scripts |
Creates a new condition (a query.Condition object) that corresponds to a logical disjunction (OR) of the arguments passed to the method. The arguments must be one or more query.Condition objects. |
|||
Client and server scripts |
Executes the query and returns the query result set. |
|||
Client and server scripts |
Executes the query asynchronously and returns the query result set. |
|||
Client and server scripts |
Executes the query and returns a set of paged results. |
|||
Client and server scripts |
Executes the query asynchronously and returns a set of paged results. |
|||
Client and server scripts |
Converts this query.Query object to its corresponding SuiteQL representation. |
|||
Property |
Object (read-only) |
Client and server scripts |
A reference to children of the root component of the query definition. The value of this property is an object of key-value pairs. Each key is the name of a child component. Each respective value is the corresponding query.Component object. |
|
Client and server scripts |
An of query result columns returned from the query. Before you perform the query, you must assign all created columns as values to this property. |
|||
query.Condition object |
Client and server scripts |
The parent condition that narrows the query results. Before you perform the query, you must assign your simple or complex conditions to this property. |
||
number (read-only) |
Client and server scripts |
The ID of the query definition. This property has a value only for existing queries that are loaded using query.load(options). If you create a query using query.create(options) but do not save it, this property is null. |
||
string (read-only) |
Client and server scripts |
The name of the query definition. This property has a value only for existing queries that are loaded using query.load(options). If you create a query using query.create(options) but do not save it, this property is null. |
||
query.Component (read-only) |
Client and server scripts |
The root component of the query definition. |
||
query.Column[] (read-only) |
Client and server scripts |
An of query result columns used for sorting. |
||
string (read-only) |
Client and server scripts |
The query type of the initial query definition. |
RelativeDate Object Members
The following members are available for a query.RelativeDate object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
string (read-only) |
Client and server scripts |
The ID of the relative date. |
|
Object (read-only) |
Client and server scripts |
The end point of the relative date. |
||
Object (read-only) |
Client and server scripts |
The interval of the relative date (from the RelativeDate.start point to the RelativeDate.end point). |
||
(read-only) |
Client and server scripts |
Whether the relative date represents a range of dates or a specific moment in time. |
||
Object (read-only) |
Client and server scripts |
The start point of the relative date. |
||
number (read-only) |
Client and server scripts |
The value of the relative date. |
Result Object Members
The following members are available for a query.Result object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Object |
Client and server scripts |
The query result as a mapped result. |
|
Property |
<string | number | | null> (read-only) |
Client and server scripts |
The result values. |
ResultSet Object Members
The following members are available for a query.ResultSet object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Object[] |
Client and server scripts |
Returns a query result set as an of mapped results. |
|
Iterator object |
Client and server scripts |
Standard SuiteScript 2.0 object for iterating through results. |
||
Property |
query.Column[] (read-only) |
Client and server scripts |
An of query result column references. |
|
query.Result[] (read-only) |
Client and server scripts |
An of query.Result objects. |
||
string[] (read-only) |
Client and server scripts |
An of the return types for ResultSet.results. |
Sort Object Members
The following members are available for a query.Sort object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Property |
boolean |
Client and server scripts |
Whether the sort direction is ascending. |
|
boolean |
Client and server scripts |
Whether the sort is case sensitive. If a sort is case sensitive (and the sort direction is ascending), rows with column values that start with uppercase letters are listed before rows with column values that start with lowercase letters. If a sort is not case sensitive, uppercase and lowercase letters are treated the same. |
||
query.Column (read-only) |
Client and server scripts |
The query result column that the query results are sorted by. |
||
string |
Client and server scripts |
The locale to use for the sort. A locale represents a combination of language and region, and it can affect how certain values (such as strings) are sorted. |
||
boolean |
Client and server scripts |
Whether query results with null values are listed at the end of the query results. |
SuiteQL Object Members
The following members are available for a query.SuiteQL object.
Member Type |
Name |
Return Type/Value Type |
Supported Script Types |
Description |
---|---|---|---|---|
Method |
Client and server scripts |
Runs the SuiteQL query and returns the query results. |
||
Client and server scripts |
Runs the SuiteQL query as a paged query and returns the paged query results. |
|||
Property |
Client and server scripts |
Describes the result columns to be returned from the query. |
||
<string | number | > (read-only) |
Client and server scripts |
Contains the parameters for the query. |
||
string (read-only) |
Client and server scripts |
Holds the string representation of the query. |
||
string (read-only) |
Client and server scripts |
Describes the type of the query. This property uses values from the query.Type enum. |