Examples

SuiteScript SuiteQL Query

Running a SuiteQL Query

SuiteScript SuiteQL query uses N/query for analytics data.

Introduction to SuiteQL

SuiteQL is a query language used within NetSuite to perform complex data analysis and retrieval operations. It is similar to SQL and is part of the SuiteScript 2.0 API, providing a powerful way to interact with NetSuite records. With SuiteQL, developers can execute queries to extract data from multiple tables and join them, enabling detailed reporting and analytics.

Setting Up Your SuiteScript Environment

Before you begin using SuiteQL, ensure you have the necessary setup in your SuiteScript environment. You need to have access to the N/query module, which is part of the SuiteScript 2.x API. Make sure your script file is correctly configured to include this module:

Basic SuiteQL Query Example

Let’s start with a simple example of a SuiteQL query. This example demonstrates how to retrieve data from the transaction table. The query will select transaction IDs and types:

Advanced SuiteQL Query: Joining Tables

SuiteQL allows you to join multiple tables to gather comprehensive insights. Here is an example that joins the transaction and customer tables to get transaction details along with customer names:

Handling Query Results

Handling query results in SuiteQL involves iterating through the result set and processing each record. The queryResults.each function allows you to access each row of data returned by the query. You can use the getValue method to extract values from each column by specifying the column name or alias.

Conclusion

SuiteQL provides a robust way to query and analyze data within NetSuite. By leveraging the capabilities of the N/query module, developers can easily perform complex data operations, facilitate better data-driven decisions, and enhance reporting capabilities. Experiment with different queries and explore the full potential of SuiteQL in your SuiteScript projects.