Supported Script Types: Server Scripts
The N/task module is used to create and manage background tasks such as Scheduled Scripts, Map/Reduce Scripts, CSV Imports, and Query Tasks.
//Creating the task to perform the scheduled script
let scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: ‘customscript_my_scheduled_script’,
deploymentId: ‘customdeploy_my_deployment’
});
let taskId = scriptTask.submit();
without calling task.submit(), the scheduled script will not run.
//See the status of the Task
Gets the current status of a submitted task.
functioncheckTaskStatus(taskId) {
let status = task.checkStatus({ taskId: taskId });
log.debug(‘Task Status’, status.status); // Possible values: PENDING, PROCESSING, COMPLETED, FAILED }
//Type of Task types
CSV_IMPORT
ENTITY_DEDUPLICATION
MAP_REDUCE
QUERY
RECORD_ACTION
SCHEDULED_SCRIPT
SEARCH
SUITE_QL
WORKFLOW_TRIGGER