发送邮件前状态检查



我有下面的脚本,我想在任务完成时发送电子邮件,我已经完全按照oracle文档指定的方式输入了检查任务行,脚本没有这些行就可以正常工作,但是当我把它们放在里面时,我得到了错误'语法错误:缺失;之前声明'

这些是导致问题的行:

let taskStatus = task.checkStatus(searchTask1);
if (taskStatus.status === 'COMPLETE')

我看不出这里缺了什么,有人能帮忙吗?谢谢你

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/task','N/email'],
/**
* @param {record} record
* @param {search} search
*/
function(task, email) {
var FILE_ID = 433961; 
var SEARCH_ID = 1610;
function execute(scriptContext) {
var searchTask1 = task.create({
taskType: task.TaskType.SEARCH
});
searchTask1.savedSearchId = SEARCH_ID;
searchTask1.fileId = FILE_ID;
var searchTaskId1 = searchTask1.submit();
let taskStatus = task.checkStatus(searchTask1);
if (taskStatus.status === 'COMPLETE'){
email.send({
author: 3499,
recipients: 'An email address',
subject: 'A subject',
body: 'body text',
});
}

您需要再次执行预定的脚本。在执行调度脚本时,将taskId保存在某个地方(例如文件柜),然后在任务完成后将其删除。您可能还希望在某个地方放置一个计数器,以便在出现问题时,调度脚本不会继续运行。像这样;

function(task, email) {
var FILE_ID = 433961;
var SEARCH_ID = 1610;
function execute(scriptContext) {
var shouldExecuteThis = false;
var searchTask1 = task.create({
taskType: task.TaskType.SEARCH
});
searchTask1.savedSearchId = SEARCH_ID;
searchTask1.fileId = FILE_ID;
var searchTaskId1 = searchTask1.submit();
// TODO: Save the searchTaskId1 somewhere so we can check the status later. (File cabinet to a text file.)
if (searchTaskId1) {
var searchTaskStatus = task.checkStatus({taskId: searchTaskId1});
// Still pending, so we need to check again later.
if (searchTaskStatus.status === task.TaskStatus.PENDING || searchTaskStatus.status === task.TaskStatus.PROCESSING) {
shouldExecuteThis = true;
}
// The task has completed, update the configuration file and log the results.
if (searchTaskStatus.status === task.TaskStatus.COMPLETE) {
// Delete the searchTaskId1 from where is it saved.
// SEND EMAIL
email.send({
author: 3499,
recipients: 'An email address',
subject: 'A subject',
body: 'body text',
});
}
if (shouldExecuteThis) {
var thisTaskId = '';
var thisTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: runtime.getCurrentScript().id,
deploymentId: runtime.getCurrentScript().deploymentId
});
try {
thisTaskId = thisTask.submit();
} catch (e) {
log.error('TASK FAILED', e);
}
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新