Introduction
“NetSuite in Five Minutes” series, Part 5. In Episode 2 “Analysis Bot”, I built a bot that delivers stable, hallucination-free answers by restricting search data to sales and interpreting natural-language queries via traditional text analysis. This time, we’re taking our first step toward the dream approach of “letting the LLM decide which records to search.”
Now, users can simply ask various questions in natural language, and the bot application automatically determines the appropriate search targets and aggregation criteria, executes the searches, and provides commentary as part of its data-analysis capabilities.
Sample Questions the Bot Can Handle
This version of the bot can answer questions such as:
1. Please tell me the top 10 customer companies by sales this year (analysis of customer sales and payments)

2. Please name the top 3 sales representatives generating the highest sales this year (sales analysis by representative and team)

3. Show me last year’s sales ranking by office (sales analysis by location, subsidiary, or department)

4. List the top 5 items by order count in the previous month (quantity analysis by product or service)

5. Which vendor had the highest purchase volume over the past six months? (purchase and payment analysis by vendor)
Technical Explanation of the Source Code
Utilizing the N/search Module
This script focuses on parameter settings for NetSuite’s standard N/search module. It automatically generates the necessary configuration items for searches (filters, grouping, sorting) to retrieve only the required data.
Flexible Mapping of Search Criteria
A mapping file named SearchCriteriaMappings.txt is used to convert natural-language questions into search queries. By associating timeframes, record types, transaction types, and more with their natural-language equivalents, this file enables flexible interpretation of user questions.
For example:
timeFrame.thisYear: this year, current year, current fiscal year, current term
recordType.customer: customer, client, client company, customer company
These entries map users’ natural expressions to NetSuite’s internal record types and search parameters. Administrators can tailor the mapping file by adding or removing keywords to fit each organization’s workflows, enabling natural-language–driven search condition configuration.
Automated Grouping and Aggregation
To support analytical questions, the script dynamically determines grouping fields and aggregation functions. For example, in response to “List the top five items by order count in the previous month,” it:
- Groups by item
- Automatically applies the COUNT aggregation function
(Note: There are cases where the expected aggregation results may not display correctly, so further improvements are needed.)
Using an LLM for Insight Generation
Beyond simply presenting search results, I leverage an LLM to generate useful insights. Based on the natural-language query and the resulting data, NetSuite’s standard N/llm module provides data analysis and commentary:
const insightsObject = llm.generateText({
prompt: prompt,
modelParameters: {
temperature: 0.5,
maxTokens: 4096
}
});
In the sample code, I also optimize prompts to stay within the free-token limit of N/llm. Since the primary feature is displaying search result data, the comments generated by N/llm are kept concise.
Future Outlook
In fact, I wrote the source code so that N/llm could also set additional search parameters beyond the mapping-based configuration. However, that part frequently hallucinated, so it remains commented out for now. The “dream approach” of delegating search-condition configuration entirely to natural language via an LLM remains just a dream—for the moment.
Still, I quess I’ve succeeded in prototyping a bot application that performs a variety of natural-language–based searches and analyses. I apologize for the somewhat unrefined source code, but I hope it serves as a helpful idea-sharing reference.
Sample Questions
Sales and Payments Analysis
1.Please tell me the top 10 customer companies by sales this year.
2. Display the top 20 customer payment transactions this year in descending order of amount.
3. What was the largest sales transaction this week?
Performance by Sales Representative and Team
4. Please name the top 3 sales representatives generating the highest sales this year.
5. Identify the sales representative with the lowest sales this month.
6. Which sales representatives had no transactions this week?
Organization-Based Analysis (Location, Subsidiary, Department)
7. Show last year’s sales ranking by office.
8. List the top 15 transactions for subsidiaries in the previous quarter.
9. Please tell me last month’s total sales by department.
10. Which top 3 regions (locations) had the highest sales this year?
Product, Service, and Order Analysis
11. List the top 5 items by order count in the previous month.
12. Display product-wise sales quantities for the previous quarter.
13. What service item was ordered the most last year?
Purchases, Payments, and Vendor Analysis
14. Which vendor had the highest purchase volume over the past six months?
15. List the top 20 vendor transactions by payment amount last month.
Reference Links
You can start using N/llm for free; no additional charges apply unless you switch to a paid mode, so feel free to try the chatbot without worry. For details on usage modes (free, on-demand, dedicated AI cluster) and other AI features, see the NetSuite Japanese Community article:
NetSuite Support Community › AI Features › SuiteScript 2.x Generative AI API
For details on N/llm and N/search, please consult the Help Center:
Oracle NetSuite Help Center > N/llm Module
Oracle NetSuite Help Center > N/search Module
