我正在尝试向页面添加一个按钮,以便在 Netsuite 上运行计划脚本。到目前为止我已经完成了一些成功的调试。发布脚本后,我在Firefox(主要浏览器,工作中的每个人都使用它)上测试了表单,发现我用来调用脚本的函数没有定义。我将其定义在 onRequest 函数之外,以便网页范围能够获取它。 我的代码:
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/task", "N/ui/serverWidget"], function(task, serverWidget) {
function onRequest(context) {
if(context.request.method === 'GET'){
var form = serverWidget.createForm({
title: 'Discrepancy Emailer Button'
});
form.addButton({
id: 'custombutton',
label: 'Send Emails',
functionName: 'executeScheduled'
});
context.response.writePage(form);
}
}
function executeScheduled() {
var scriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: "customscriptXXXX",
deploymentId: "customdeploy1"
});
var scriptTaskId = scriptTask.submit();
log.debug("scriptTaskId", scriptTaskId);
}
return {
onRequest: onRequest
};`
```
The error I receive:
[Uncaught ReferenceError: executeScheduled is not defined
onclick scriptlet.nl:1
execCb NsRequire.js:2047
check NsRequire.js:1193
enable NsRequire.js:1475
init NsRequire.js:1106
h NsRequire.js:1771
setTimeout handler*w.nextTick/< NsRequire.js:2216
nextTick NsRequire.js:2218
h NsRequire.js:1760
requirejs NsRequire.js:2167
require bootstrap.js:155
onclick scriptlet.nl:1
scriptlet.nl:1:25
](https://i.stack.imgur.com/CYDH8.png)
I would first like to understand why the error occurs as well as what I would have to change to fix it. Thank you all very much for your time.
I have tried moving the 'executeScheduled' function before and after the button declaration, changing the type of button to a submit button, using a client side script, adding it as part of the post request and declaring the task separately. I was expecting the scheduled script to run.
Suitelet 在 NetSuite 服务器上执行 - 其中的代码不可用于浏览器。处理您的用例的方法是将客户端脚本附加到您要返回的表单,并将要从按钮执行的函数放入该客户端脚本中。
form.clientScriptModulePath = 'SuiteScripts/path/to/client_script'; //file cabinet path to client script file
或
form.clientScriptFileId = 12345; //internal id of client script file in your file cabinet