在套件上点击的按钮上触发客户端脚本? [英] Trigger a client script on a button clicked on a Suitelet?
本文介绍了在套件上点击的按钮上触发客户端脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据在套件上单击的按钮更新自定义记录上的值
这将有3或4个不同的按钮。
只有一个设置页面可以在单击该按钮时加载。
例如,在Suitlet上点击‘Recurning’。这将加载一个自定义记录页面并设置参数。 如果单击‘半周发票’按钮,则还将加载相同的自定义记录页面并设置参数。
我遇到困难的地方:我有一个Suitlet,其中的按钮旨在通过调用客户端脚本函数来加载自定义记录
相反,Suitlet一加载,自定义记录页面就会加载并一次又一次地陷入无限循环重新加载
这是我的套件脚本:
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/ui/serverWidget"], function (ui) {
var exports = {};
function onRequest(context) {
if (context.request.method === "GET") {
var form = ui.createForm({
title: "Consolidated Invoicing Type",
});
// form.clientScriptModulePath =
// "SuiteScripts/sdf_ignore/Consolidated Invoice Client Script.js";
form.clientScriptFileId = 2659;
form.addButton({
id: "recurring",
label: "Recurring",
functionName: "pageInit",
});
context.response.writePage(form);
} else if ((context.response.method = "POST")) {
log.debug({
title: "request method type",
details: "suitelet is posting",
});
}
}
exports.onRequest = onRequest;
return exports;
});
这是客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/runtime", "N/url"], function (
record,
runtime,
url
) {
/**
* @param {ClientScriptContext.pageInit} context
*/
function pageInit(context) {
var scriptObj = runtime.getCurrentScript();
var recordType = scriptObj.getParameter("custscript_ci_suitelet_record");
var pageUrl =
"https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=T";
var url = new URL(pageUrl);
window.location.href = url;
}
return {
pageInit: pageInit,
};
});
我是否需要使用其他脚本类型来设置自定义记录上的值?(即不是客户端脚本)
如何将用户事件脚本链接到套件,以便在单击按钮时触发它?
如果客户端脚本应该绑定到表单上的按钮,为什么在加载Suitlet页面时会自动启动它?
谢谢
推荐答案
页面不断重新加载,因为客户端脚本中的&pageInit";函数将由NetSuite自动执行,因为";pageInit";是默认的NetSuite条目函数。如果您只需重命名您的函数,它将起作用:
在套装上:
form.addButton({
id: "recurring",
label: "Recurring",
functionName: "executeRecurring",
});
在客户端脚本上:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/runtime", "N/url"], function (
record,
runtime,
url
) {
/**
* @param {ClientScriptContext.pageInit} context
*/
function executeRecurring() {
var scriptObj = runtime.getCurrentScript();
var recordType = scriptObj.getParameter("custscript_ci_suitelet_record");
var pageUrl =
"https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=143&id=1&e=T";
var url = new URL(pageUrl);
window.location.href = url;
}
function pageInit(context) { // you need to keep at least one Netsuite Entry function, otherwise you will get an error
}
return {
pageInit: pageInit,
executeRecurring: executeRecurring
};
});
另外,如果参数securp_ci_suitlets_record是Suitlet脚本上的参数,则您将无法在客户端脚本上获取其值,您必须在Suitlet脚本上获取该值并在按钮调用期间将其作为参数传递:
套装:
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/ui/serverWidget", "N/runtime"], function (ui, runtime) {
var exports = {};
function onRequest(context) {
if (context.request.method === "GET") {
var form = ui.createForm({
title: "Consolidated Invoicing Type",
});
// form.clientScriptModulePath =
// "SuiteScripts/sdf_ignore/Consolidated Invoice Client Script.js";
form.clientScriptFileId = 2659;
var recordType = runtime.getCurrentScript().getParameter("custscript_ci_suitelet_record");
form.addButton({
id: "recurring",
label: "Recurring",
functionName: "executeRecurring('" + recordType + "')",
});
context.response.writePage(form);
} else if ((context.response.method = "POST")) {
log.debug({
title: "request method type",
details: "suitelet is posting",
});
}
}
exports.onRequest = onRequest;
return exports;
});
客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/runtime", "N/url"], function (
record,
runtime,
url
) {
/**
* @param {ClientScriptContext.pageInit} context
*/
function executeRecurring(recType) {
var pageUrl =
"https://tstdrv.app.netsuite.com/app/common/custom/custrecordentry.nl?rectype=" + recType + "&id=1&e=T";
var url = new URL(pageUrl);
window.location.href = url;
}
function pageInit(context) { // you need to keep at least one Netsuite Entry function, otherwise you will get an error
}
return {
pageInit: pageInit,
executeRecurring: executeRecurring
};
});
这篇关于在套件上点击的按钮上触发客户端脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文