Query Object Members for SuiteScript 2.1 Integration
Query object members in SuiteScript enable flexible data retrieval through various methods, conditions, and joins.
Starting with the Query object in SuiteScript, developers can create complex data retrieval requests efficiently. This functionality is critical for customizing data access in applications and streamlining operations.
What Are Query Object Members?
The query.Query object provides developers with a structured way to construct queries in SuiteScript. This object is central to the N/query module and offers various members that facilitate data interactions. Below is an overview of the key members available for the query.Query object:
Methods
| Method | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|
Query.and(conditions) | query.Condition | Client and server scripts | Creates a new condition that represents a logical conjunction (AND) of provided conditions. |
Query.autoJoin(options) | query.Component | Client and server scripts | Automatically creates a join relationship based on record types. |
Query.createColumn(options) | query.Column | Client and server scripts | Generates a result column based on the initial query object. |
Query.createCondition(options) | query.Condition | Client and server scripts | Defines a condition for the initial query object. |
Query.createSort(options) | query.Sort | Client and server scripts | Establishes a sort order based on specified query result columns. |
Query.join(options) | query.Component | Client and server scripts | Defines a join relationship; an alias for Query.autoJoin(options). |
Query.run(options) | query.ResultSet | Client and server scripts | Executes the query and returns the results. |
Query.toSuiteQL() | query.SuiteQL | Client and server scripts | Converts the query object to its SuiteQL representation. |
Properties
| Property | Return Type | Description |
|---|---|---|
Query.child | Object (read-only) | A reference to the child components of the query. |
Query.columns | query.Column[] | An array of columns returned from the query. |
Query.condition | query.Condition | The main condition that filters the returned results. |
Query.id | number (read-only) | The unique identifier for the query, available for loaded queries. |
Query.name | string (read-only) | The name of the query, available for loaded queries. |
Query.root | query.Component (read-only) | The root component of the query definition. |
Query.sort | query.Column[] (read-only) | An array of columns used for sorting. |
How to Use the Query Object
To utilize the query.Query object effectively:
- Create a Query Definition: Use
query.create(options)to initiate a new query. - Define Conditions: Utilize methods like
Query.createCondition(options)to set up filters. - Add Joins: Employ
Query.autoJoin(options)to manage relationships between different record types. - Execute the Query: Finally, run the query using
Query.run(options)or access it asynchronously withQuery.run.promise().
Key Considerations
When working with the Query object, consider the following best practices:
- Ensure all conditions and columns are defined before executing a query.
- Leverage the automatic join capabilities to simplify code and reduce errors.
- Familiarize yourself with the
query.Conditionstructure to create more complex filters easily.
Key Takeaways:
- The
query.Queryobject is essential for building complex retrieval queries in SuiteScript. - Understanding its methods and properties can significantly enhance data interaction capabilities.
- Utilize auto-joins and async execution options for efficient scripts.
Frequently Asked Questions (4)
What script types support the Query object methods in SuiteScript?
How can I define conditions for a query in SuiteScript using the Query object?
Does the Query object in SuiteScript support converting queries to SuiteQL?
Can I use the Query object to automatically create join relationships in SuiteScript?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
