我怎样才能用一个按钮启动一个预定的脚本?
How can i start a scheduled script with a button?
我想在执行预定脚本的表单中创建一个按钮,但我尝试的任何方法都不起作用
我已经尝试使用 addButton 方法来调用为预定脚本创建任务的函数,但它仅在表单加载时执行
/**
*@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
});
我最后做到了。它正在创建 3 个脚本,一个调用客户端脚本的用户事件,它使用为预定脚本创建任务的函数向套件发出获取请求
这是用户事件:
/**
*@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
};
});
这是套房:
/**
*@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
};
});
我希望这对遇到同样问题的另一个人有所帮助。
我想在执行预定脚本的表单中创建一个按钮,但我尝试的任何方法都不起作用
我已经尝试使用 addButton 方法来调用为预定脚本创建任务的函数,但它仅在表单加载时执行
/**
*@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
});
我最后做到了。它正在创建 3 个脚本,一个调用客户端脚本的用户事件,它使用为预定脚本创建任务的函数向套件发出获取请求
这是用户事件:
/**
*@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
};
});
这是套房:
/**
*@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
};
});
我希望这对遇到同样问题的另一个人有所帮助。