/**
* @NApiVersion 2.1
*/
require([‘N/task’, ‘N/runtime’, ‘N/email’], (task, runtime, email) => {
// Store the script ID of the script to submit
//
// Update the following statement so it uses the script ID
// of the map/reduce script record you want to submit
const mapReduceScriptId = ‘customscript_test_mapreduce_script’;
// Create a map/reduce task
//
// Update the deploymentId parameter to use the script ID of
// the deployment record for your map/reduce script
let mrTask = task.create({
taskType: task.TaskType.MAP_REDUCE,
scriptId: mapReduceScriptId,
deploymentId: ‘customdeploy_test_mapreduce_script’
});
// Submit the map/reduce task
let mrTaskId = mrTask.submit();
// Check the status of the task, and send an email if the
// task has a status of FAILED
//
// Update the authorId value with the internal ID of the user
// who is the email sender. Update the recipientEmail value
// with the email address of the recipient.
let taskStatus = task.checkStatus(mrTaskId);
if (taskStatus.status === ‘FAILED’) {
const authorId = -5;
const recipientEmail = ‘notify@myCompany.com’;
email.send({
author: authorId,
recipients: recipientEmail,
subject: ‘Failure executing map/reduce job!’,
body: ‘Map reduce task: ‘ + mapReduceScriptId + ‘ has failed.’
});
}
});