Query Object Members for SuiteScript 2.1 Data Retrieval
Query object members in SuiteScript enable flexible data retrieval via 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 Integration
- Loop Returns Integration in NetSuite Connector 2026.1
Updated to include features of the Loop Returns integration in NetSuite Connector 2026.1. Loop Returns Integration in NetSuite Connector 2026.1
- Create Integration Records for OAuth 2.0 in NetSuite 2026.1
In NetSuite 2026.1, administrators can create integration records for applications to use OAuth 2.0, enabling secure access. Here's how.
- Square Connector Integration in NetSuite 2026.1
Discover the Square Connector for seamless integration with NetSuite 2026.1, synchronizing transactions, orders, and inventory effortlessly.
- SuiteTalk Web Services Updates for NetSuite Integrations
SuiteTalk Web Services adds new Item Supply Plan support, enhancing integrations for efficient data management.
Advertising
Reach Integration Professionals
Put your product in front of NetSuite experts who work with Integration every day.
Sponsor This Category