Query Object Members for SuiteScript 2.1 Integration

Query object members in SuiteScript enable flexible data retrieval through various methods, conditions, and joins.

·3 min read·View Oracle Docs

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

MethodReturn Type / Value TypeSupported Script TypesDescription
Query.and(conditions)query.ConditionClient and server scriptsCreates a new condition that represents a logical conjunction (AND) of provided conditions.
Query.autoJoin(options)query.ComponentClient and server scriptsAutomatically creates a join relationship based on record types.
Query.createColumn(options)query.ColumnClient and server scriptsGenerates a result column based on the initial query object.
Query.createCondition(options)query.ConditionClient and server scriptsDefines a condition for the initial query object.
Query.createSort(options)query.SortClient and server scriptsEstablishes a sort order based on specified query result columns.
Query.join(options)query.ComponentClient and server scriptsDefines a join relationship; an alias for Query.autoJoin(options).
Query.run(options)query.ResultSetClient and server scriptsExecutes the query and returns the results.
Query.toSuiteQL()query.SuiteQLClient and server scriptsConverts the query object to its SuiteQL representation.

Properties

PropertyReturn TypeDescription
Query.childObject (read-only)A reference to the child components of the query.
Query.columnsquery.Column[]An array of columns returned from the query.
Query.conditionquery.ConditionThe main condition that filters the returned results.
Query.idnumber (read-only)The unique identifier for the query, available for loaded queries.
Query.namestring (read-only)The name of the query, available for loaded queries.
Query.rootquery.Component (read-only)The root component of the query definition.
Query.sortquery.Column[] (read-only)An array of columns used for sorting.

How to Use the Query Object

To utilize the query.Query object effectively:

  1. Create a Query Definition: Use query.create(options) to initiate a new query.
  2. Define Conditions: Utilize methods like Query.createCondition(options) to set up filters.
  3. Add Joins: Employ Query.autoJoin(options) to manage relationships between different record types.
  4. Execute the Query: Finally, run the query using Query.run(options) or access it asynchronously with Query.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.Condition structure to create more complex filters easily.

Key Takeaways:

  • The query.Query object 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.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

What script types support the Query object methods in SuiteScript?
The Query object methods are supported in both client and server scripts.
How can I define conditions for a query in SuiteScript using the Query object?
You can define conditions by using the 'Query.createCondition(options)' method which sets up filters for the initial query object.
Does the Query object in SuiteScript support converting queries to SuiteQL?
Yes, the Query object supports conversion to SuiteQL using the 'Query.toSuiteQL()' method.
Can I use the Query object to automatically create join relationships in SuiteScript?
Yes, you can automatically create join relationships by using the 'Query.autoJoin(options)' method, which is also aliased by 'Query.join(options)'.
Source: Query Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →