task.create(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a task object for the specified task type and returns the object.

Use this method to create tasks to do the following:

  • Schedule scripts

  • Run map/reduce scripts

  • Import CSV files

  • Merge duplicate records

  • Execute asynchronous searches, constructed queries, SuiteQL queries, and workflows

Returns

task.CsvImportTask | task.EntityDeduplicationTask | task.MapReduceScriptTask | task.RecordActionTask | task.QueryTask | task.ScheduledScriptTask | task.SearchTask | task.SuiteQLTask | task.WorkflowTriggerTask

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/task Module

Since

2015.2

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.taskType

string

required

The type of task object to create.

Use the task.TaskType enum to set the value.

options.deploymentId

string

optional

The script ID (as a string) of the script deployment record.

This parameter sets the value for the ScheduledScriptTask.deploymentId or MapReduceScriptTask.deploymentId property.

This parameter is applicable only when options.taskType is set to task.TaskType.SCHEDULED_SCRIPT or task.TaskType.MAP_REDUCE.

options.params

Object | Array<string | boolean | number>

optional

An object that represents additional parameters and values for the task.

This parameter accepts different values based on the value of the options.taskType parameter:

  • If options.taskType is set to task.TaskType.SCHEDULED_SCRIPT, task.TaskType.MAP_REDUCE or task.TaskType.WORKFLOW_TRIGGER, this parameter accepts key-value pairs that override static script parameter field values on the script deployment record. For more information, see Creating Script Parameters Overview. For workflow tasks, keys can include fields on the Workflow Definition Page, or workflow and state custom fields. For more information, see Workflow Custom Fields.

  • If options.taskType is set to task.TaskType.SUITE_QL, this parameter accepts an array of parameters for the associated SuiteQL query. The specified parameters are substituted into the SuiteQL query string when you submit the task.

This parameter sets the value for the ScheduledScriptTask.params, MapReduceScriptTask.params, WorkflowTriggerTask.params, or SuiteQLTask.params properties.

This parameter is applicable only when options.taskType is set to task.TaskType.SCHEDULED_SCRIPT, task.TaskType.MAP_REDUCE, task.TaskType.WORKFLOW_TRIGGER, or task.TaskType.SUITE_QL.

options.scriptId

number | string

optional

The internal ID (as a number) or script ID (as a string) for the script record.

This parameter sets the value for the ScheduledScriptTask.scriptId or MapReduceScriptTask.scriptId property.

This parameter is applicable only when options.taskType is set to task.TaskType.SCHEDULED_SCRIPT or task.TaskType.MAP_REDUCE.

options.importFile

file.File | string

optional

A CSV file to import. Use a file.File object or a string that represents the CSV text to be imported.

This parameter sets the value for the CsvImportTask.importFile property.

This parameter is applicable only when options.taskType is set to task.TaskType.CSV_IMPORT.

options.linkedFiles

Object

optional

A map of key-value pairs that sets the data to be imported in a linked file for a multi-file import job, by referencing a file in the File Cabinet or the raw CSV data to import.

The key is the internal ID of the record sublist for which data is being imported and the value is either a file.File object or the raw CSV data to import.

You can assign multiple types of values to this property.

This parameter sets the value for the CsvImportTask.linkedFiles property.

This parameter is applicable only when options.taskType is set to task.TaskType.CSV_IMPORT.

options.mappingId

number | string

optional

The internal ID (as a number) or script ID (as a string) of a saved import map created using the Import Assistant. See task.CsvImportTask.

This parameter sets the value for the CsvImportTask.mappingId property.

This parameter is applicable only when options.taskType is set to task.TaskType.CSV_IMPORT.

options.name

string

optional

The name for the CSV import task.

You can optionally set a different name for a scripted import task. In the UI, this name appears on the CSV Import Job Status page.

This parameter sets the value for the CsvImportTask.name property.

This parameter is applicable only when options.taskType is set to task.TaskType.CSV_IMPORT.

options.queueId

number

optional

Overrides the Queue Number property under Advanced Options on the Import Options page of the Import Assistant. Use this property to programmatically select an import queue and improve performance during the import.

Note:

This property is only available if you have a SuiteCloud Plus license. For more information about using multiple queues when importing CSV files, see Queue Number and Use Multiple Threads and Multiple Queues to Run CSV Import Jobs.

This parameter sets the value for the CsvImportTask.queueId property.

This parameter is applicable only when options.taskType is set to task.TaskType.CSV_IMPORT.

options.dedupeMode

string

optional

Sets the mode for merging or deleting duplicate records.

This parameter sets the value for the EntityDeduplicationTask.dedupeMode property.

This parameter is applicable only when options.taskType is set to task.TaskType.ENTITY_DEDUPLICATION.

Use the task.DedupeMode enum to set the value.

options.entityType

string

optional

Sets the type of entity on which you want to merge duplicate records.

This parameter sets the value for the EntityDeduplicationTask.entityType property.

This parameter is applicable only when options.taskType is set to task.TaskType.ENTITY_DEDUPLICATION.

Use the task.DedupeEntityType enum to set the value.

Note:

If you specify a value of CUSTOMER for this parameter, NetSuite automatically includes prospects and leads in the task request.

options.masterRecordId

number

optional

When you merge duplicate records, you can delete all duplicates for a record or merge information from the duplicate records into the master record.

Use this property to set the ID of the master record that you want to use as the master record in the merge.

Important:

You must also select SELECT_BY_ID for the EntityDeduplicationTask.masterSelectionMode property, or NetSuite ignores this setting.

This parameter sets the value for the EntityDeduplicationTask.masterRecordId property.

This parameter is applicable only when options.taskType is set to task.TaskType.ENTITY_DEDUPLICATION.

options.masterSelectionMode

string

optional

When you merge duplicate records, you can delete all duplicates for a record or merge information from the duplicate records into the master record.

Set this property to determine which of the duplicate records to keep or to select the master record to use by ID.

This parameter sets the value for the EntityDeduplicationTask.masterSelectionMode property.

This parameter is applicable only when options.taskType is set to task.TaskType.ENTITY_DEDUPLICATION.

Use the task.MasterSelectionMode enum to set the value.

options.recordIds

number[]

optional

The internal IDs of the records to perform the merge or delete operation on.

You can use the search.duplicates(options) method to identify duplicate records or create an array with record internal IDs.

This parameter sets the value for the EntityDeduplicationTask.recordIds property.

This parameter is applicable only when options.taskType is set to task.TaskType.ENTITY_DEDUPLICATION.

options.recordId

number

optional

The internal ID of the base record.

This parameter sets the value for the WorkflowTriggerTask.recordId property.

This parameter is applicable only when options.taskType is set to task.TaskType.WORKFLOW_TRIGGER.

options.recordType

string

optional

The record type of the workflow definition base record, such as customer, salesorder, or lead.

In the Workflow Manager, this is the record type that is specified in the Record Type field.

This parameter sets the value for the WorkflowTriggerTask.recordType property.

This parameter is applicable only when options.taskType is set to task.TaskType.WORKFLOW_TRIGGER.

options.workflowId

number | string

optional

The internal ID (as a number) or script ID (as a string) for the workflow definition.

This is the ID that appears in the ID field on the Workflow Definition Page.

This parameter sets the value for the WorkflowTriggerTask.workflowId property.

This parameter is applicable only when options.taskType is set to task.TaskType.WORKFLOW_TRIGGER.

options.fileId

number

optional

The internal ID of the CSV file to export search results to. For more information about working with files, see N/file Module.

This parameter is mutually exclusive with the options.filePath parameter. If you specify values for both parameters, an error occurs.

This parameter sets the value for the SearchTask.fileId, QueryTask.fileId, or SuiteQLTask.fileId properties.

This parameter is applicable only when options.taskType is set to task.TaskType.SEARCH, task.TaskType.QUERY, or task.TaskType.SUITE_QL.

options.filePath

string

optional

The path of the CSV file to export search results to. For more information about working with files, see N/file Module.

This parameter is mutually exclusive with the options.fileId parameter. If you specify values for both parameters, an error occurs.

This parameter sets the value for the SearchTask.filePath, QueryTask.filePath, or SuiteQLTask.filePath properties.

This parameter is applicable only when options.taskType is set to task.TaskType.SEARCH, task.TaskType.QUERY, or task.TaskType.SUITE_QL.

options.query

query.Query | string

optional

The query definition for a query task or SuiteQL task.

This parameter accepts different values based on the value of the options.taskType parameter:

  • If options.taskType is set to task.TaskType.QUERY, this parameter accepts a query.Query object that represents the query to run.

  • If options.taskType is set to task.TaskType.SUITE_QL, this parameter accepts a string that represents the SuiteQL query to run.

This parameter sets the value for the QueryTask.query or SuiteQLTask.query properties.

This parameter is applicable only when options.taskType is set to task.TaskType.QUERY or task.TaskType.SUITE_QL.

options.savedSearchId

string

optional

The internal ID of the saved search to be executed during the task.

This parameter sets the value for the SearchTask.savedSearchId property.

This parameter is applicable only when options.taskType is set to task.TaskType.SEARCH.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/task Module Script Samples.

            // Add additional code ...
var mrTask = task.create({
    taskType: task.TaskType.MAP_REDUCE,
    scriptId: 34,
    deploymentId: 'custdeploy1',
    params: { doSomething: true }
});
...
// Add additional code 

          

Related Topics

N/task Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices