Button 如何使用按钮启动计划脚本?
我想在表单中创建一个按钮,执行计划脚本,但我尝试的任何操作都不起作用 我尝试了addButton方法来调用一个函数,该函数为scheluded脚本创建一个任务,但它只在表单加载时执行Button 如何使用按钮启动计划脚本?,button,netsuite,suitescript,Button,Netsuite,Suitescript,我想在表单中创建一个按钮,执行计划脚本,但我尝试的任何操作都不起作用 我尝试了addButton方法来调用一个函数,该函数为scheluded脚本创建一个任务,但它只在表单加载时执行 /** *@NApiVersion 2.x *@NScriptType UserEventScript */ define(["N/task", "N/ui/serverWidget"], function(task, serverWidget) { function beforeLoad(context
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(["N/task", "N/ui/serverWidget"], function(task, serverWidget) {
function beforeLoad(context) {
context.form.addButton({
id: "custpage_setTask",
label: "Execute scheduled",
functionName: executeScheduled()
});
}
return {
beforeLoad: beforeLoad
};
function executeScheduled() {
var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscript_sdr_ss_product_shortage',
deploymentId: 'customdeployprodshortsearch'
});
var scriptTaskId = scriptTask.submit();
log.debug('scriptTaskId', scriptTaskId);
}
});
执行预定脚本,但仅在表单加载中执行,然后按钮不执行任何操作,请提供帮助并感谢阅读我相信您还需要导出按钮功能
return {
beforeLoad: beforeLoad,
executeScheduled:executeScheduled
};
您还需要更改按钮选项
context.form.addButton({
id: "custpage_setTask",
label: "Execute scheduled",
functionName: executeScheduled
});
我相信您还需要导出按钮功能
return {
beforeLoad: beforeLoad,
executeScheduled:executeScheduled
};
您还需要更改按钮选项
context.form.addButton({
id: "custpage_setTask",
label: "Execute scheduled",
functionName: executeScheduled
});
我终于做到了。它创建了3个脚本,这是一个调用客户端脚本的用户事件,通过为计划脚本创建任务的函数向suitelet发出get请求 这是用户事件:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(["N/task", "N/ui/serverWidget"], function(task, serverWidget) {
function beforeLoad(context) {
// internal id of the client script on file cabinet
context.form.clientScriptFileId = 2343;
context.form.addButton({
id: "custpage_setTask",
label: "Execute scheduled",
functionName: 'redirect'
});
}
return {
beforeLoad: beforeLoad,
};
});
这是客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/url", "N/https"], function(url, https) {
function pageInit(context) {}
function redirect() {
var output = url.resolveScript({
scriptId: "customscript_sss_sl_startschedulescript",
deploymentId: "customdeploy_sss_sl_startschedulescript"
});
log.debug('url', output);
var response = https.get({
url: output
});
log.debug('response', response);
}
return {
pageInit: pageInit,
redirect: redirect
};
});
这是suitelet:
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/task"], function(task) {
function onRequest(context) {
executeScheduled();
}
function executeScheduled() {
var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: "customscript_sdr_ss_product_shortage",
deploymentId: "customdeployprodshortsearch"
});
var scriptTaskId = scriptTask.submit();
log.debug("scriptTaskId", scriptTaskId);
}
return {
onRequest: onRequest
};
});
我希望这能帮助另一个有同样问题的人。最后我设法做到了。它创建了3个脚本,这是一个调用客户端脚本的用户事件,通过为计划脚本创建任务的函数向suitelet发出get请求 这是用户事件:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(["N/task", "N/ui/serverWidget"], function(task, serverWidget) {
function beforeLoad(context) {
// internal id of the client script on file cabinet
context.form.clientScriptFileId = 2343;
context.form.addButton({
id: "custpage_setTask",
label: "Execute scheduled",
functionName: 'redirect'
});
}
return {
beforeLoad: beforeLoad,
};
});
这是客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/url", "N/https"], function(url, https) {
function pageInit(context) {}
function redirect() {
var output = url.resolveScript({
scriptId: "customscript_sss_sl_startschedulescript",
deploymentId: "customdeploy_sss_sl_startschedulescript"
});
log.debug('url', output);
var response = https.get({
url: output
});
log.debug('response', response);
}
return {
pageInit: pageInit,
redirect: redirect
};
});
这是suitelet:
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/task"], function(task) {
function onRequest(context) {
executeScheduled();
}
function executeScheduled() {
var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: "customscript_sdr_ss_product_shortage",
deploymentId: "customdeployprodshortsearch"
});
var scriptTaskId = scriptTask.submit();
log.debug("scriptTaskId", scriptTaskId);
}
return {
onRequest: onRequest
};
});
我希望这有助于解决另一个同样的问题。当我单击按钮时,控制台中出现“未捕获的SyntaxError:无效或意外的令牌”错误;当我单击按钮时,控制台中出现“未捕获的SyntaxError:无效或意外的令牌”错误您需要运行executeScheduled()函数。您需要在单独的客户端脚本中运行executeScheduled()函数。