N/query Module Members in SuiteScript for NetSuite

The N/query module in SuiteScript provides members for querying data. This includes creating query definitions, conditions, and handling result sets.

·3 min read·View Oracle Docs

The N/query module in SuiteScript serves as an interface for constructing database queries within NetSuite. With various object members and methods, developers can efficiently retrieve and manipulate data. Understanding these components is crucial for leveraging the full power of SuiteScript in query operations.

What Are N/query Module Members?

The N/query module includes several members that facilitate the creation and handling of database queries. Here’s a breakdown of its key components:

Member NameTypeReturn TypeDescription
query.ColumnObjectObjectRepresents a column in the query result set. Use to define query fields.
query.ComponentObjectObjectRepresents a component in the query definition, including relationships for joins.
query.ConditionObjectObjectA condition to filter query results.
query.PageObjectObjectRepresents a single page of paged query results.
query.PagedDataObjectObjectEncapsulates a set of paged query results.
query.QueryObjectObjectThe overall query definition.
query.ResultObjectObjectRepresents a row of results from the query.
query.ResultSetObjectObjectThe collection of results returned by the query.
query.SortObjectObjectSpecifies the sorting criteria for the query results.
query.SuiteQLObjectObjectAllows executing SuiteQL based queries.

Key Methods of the N/query Module

Supporting the functionality of the module are several important methods:

  • Creating Queries: Use query.create(options) to define the query structure. This method requires at least one column to be defined.
  • Loading Existing Queries: Utilize query.load(options) to load queries created in the SuiteAnalytics Workbook UI for modification and execution.
  • Running Queries: The query.runSuiteQL(options) method allows executing arbitrary SuiteQL queries directly, returning the results according to specified parameters.

Important Considerations

  • Essential Column Requirement: At least one query.Column object must be present in every query definition to avoid scripting errors. It is essential for data retrieval and manipulation within SuiteScript.
  • Script Compatibility: All components of the N/query module support both client and server scripts, offering flexibility in how scripts are deployed and executed within NetSuite.

Example Usage

suitescript
1var myCustomerQuery = query.create({
2 type: query.Type.CUSTOMER
3});
4
5myCustomerQuery.columns = [
6 myCustomerQuery.createColumn({
7 fieldId: 'internalid'
8 }),
9 myCustomerQuery.createColumn({
10 fieldId: 'entityid'
11 })
12];
13
14var results = myCustomerQuery.run();

This code demonstrates the creation of a customer query and retrieval of selected columns' data.

Key Takeaways

  • The N/query module provides comprehensive tools for data query operations in SuiteScript.
  • Key members and methods include query.Column, query.Condition, and several methods for query execution.
  • Valid usage of the module requires understanding the components and their relationships.

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

Frequently Asked Questions (4)

Does the N/query module support both client and server scripts in NetSuite?
Yes, all components of the N/query module support both client and server scripts, providing flexibility in script deployment and execution within NetSuite.
What is a mandatory component when creating a query with the N/query module?
At least one query.Column object must be defined in every query when using the query.create(options) method to avoid scripting errors and ensure data retrieval.
How can I execute a SuiteQL query using the N/query module?
You can execute a SuiteQL query using the query.runSuiteQL(options) method, which allows executing arbitrary SuiteQL queries directly and returning the results based on specified parameters.
Is it possible to load and modify existing queries created in the SuiteAnalytics Workbook UI?
Yes, the N/query module allows you to load existing queries created in the SuiteAnalytics Workbook UI using the query.load(options) method for modification and execution.
Source: N/query Module 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 →