N/query Module Members in SuiteScript for NetSuite
N/query module members in SuiteScript enable efficient database queries and data manipulation in NetSuite.
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 Name | Type | Return Type | Description |
|---|---|---|---|
query.Column | Object | Object | Represents a column in the query result set. Use to define query fields. |
query.Component | Object | Object | Represents a component in the query definition, including relationships for joins. |
query.Condition | Object | Object | A condition to filter query results. |
query.Page | Object | Object | Represents a single page of paged query results. |
query.PagedData | Object | Object | Encapsulates a set of paged query results. |
query.Query | Object | Object | The overall query definition. |
query.Result | Object | Object | Represents a row of results from the query. |
query.ResultSet | Object | Object | The collection of results returned by the query. |
query.Sort | Object | Object | Specifies the sorting criteria for the query results. |
query.SuiteQL | Object | Object | Allows 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.Columnobject 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
1var myCustomerQuery = query.create({2 type: query.Type.CUSTOMER3});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.
Frequently Asked Questions (4)
Does the N/query module support both client and server scripts in NetSuite?
What is a mandatory component when creating a query with the N/query module?
How can I execute a SuiteQL query using the N/query module?
Is it possible to load and modify existing queries created in the SuiteAnalytics Workbook UI?
Was this article helpful?
More in SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
- Enhancements to SuiteScript User Role Context Clarification
SuiteScript updates clarify the user and role contexts for script executions, improving deployment understanding and management.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category