N/task Module for Managing Asynchronous Tasks in NetSuite
N/task module allows asynchronous task creation and management in NetSuite, including CSV imports, script executions, and more.
TL;DR
The N/task module in NetSuite enables developers to manage asynchronous tasks such as executing scripts, performing CSV imports, and running workflows. This module provides specific object types and methods for creating, submitting, and monitoring diverse task operations efficiently.
What is the N/task Module?
The N/task module is a part of NetSuite's SuiteScript development framework, designed for creating and handling scheduled tasks. This module is essential for implementing background operations that do not require immediate user interaction. It facilitates a range of operations, such as:
- Submitting scheduled scripts
- Running map/reduce scripts
- Importing CSV files
- Merging duplicate records
- Executing asynchronous searches and workflows
Each task defined in this module is triggered asynchronously, meaning that it does not block the main script processing and allows for parallel execution of operations. This is crucial for maintaining performance and responsiveness within NetSuite.
Available Task Types
The N/task module provides specific task types, each with corresponding object members. Below is a summary of the task types:
| Task Type | Description |
|---|---|
task.CsvImportTask | Properties for a CSV import task. |
task.DocumentCaptureTask | Properties for a document capture task. |
task.EntityDeduplicationTask | Properties for merging duplicate records. |
task.MapReduceScriptTask | Properties related to map/reduce script deployments. |
task.QueryTask | Properties for executing a query task. |
task.RecordActionTask | Properties for actions on records. |
task.ScheduledScriptTask | Properties for scheduled script tasks. |
task.SearchTask | Properties for initiating asynchronous searches. |
task.SuiteQLTask | Properties for SuiteQL query tasks. |
task.WorkflowTriggerTask | Properties for initiating workflows asynchronously. |
These tasks can be submitted into the task queue, which NetSuite processes in the background.
Important Methods
Each task type includes methods for creating and checking the status of tasks. Key methods include:
task.checkStatus(options): Checks the status of a task identified by its task ID.task.create(options): Creates an object for a specific task type, preparing it for submission to the task queue.
Example of Submitting a CSV Import Task
Here’s a quick example demonstrating how to submit a CSV import task:
1require(['N/task'], function(task) {2 var csvImportTask = task.create({taskType: task.TaskType.CSV_IMPORT});3 csvImportTask.importFile = file.create({name: 'data.csv'});4 var taskId = csvImportTask.submit();5 log.debug('CSV Import Task ID:', taskId);6});Who This Affects
This module is particularly useful for:
- Developers: For implementing background processes and enhancing performance.
- Administrators: For managing data imports and scheduled tasks effectively.
- Business Analysts: For automating reporting and data management workflows.
Key Takeaways
- The N/task module is designed for managing asynchronous tasks in NetSuite.
- Supports various operations like CSV imports and script executions.
- Each task type has specific properties and methods for effective management.
- Asynchronous processing enhances system performance and responsiveness.
Frequently Asked Questions (4)
What are the prerequisites for using the N/task module in NetSuite?
Can the N/task module be used to run map/reduce scripts in parallel?
How do I check the status of a task created with the N/task module?
Does the N/task module support importing CSV files asynchronously?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
