提交时关闭 Suitelet window
Close a Suitelet window on submit
我正在尝试在 suitelet 上使用 window.close() 作为 post 响应的一部分。
suitelet 是从客户端脚本打开的弹出窗口。
这是客户端脚本的相关部分:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/url", "N/currentRecord"], function (
record,
url,
currentRecord
) {
/**
* @param {ClientScriptContext.pageInit} context
* @param {ClientScriptContext.onclick_callforSuitelet} context
*/
function pageInit() {}
function onclick_callforSuitelet() {
var record = currentRecord.get();
var recordId = record.id;
var recordType = record.type;
log.debug("recId", recordId);
log.debug("recType", recordType);
//this is the script id on the script record for the suitelet (not the deployment)
var suiteletURL = url.resolveScript({
scriptId: "customscript_suitelet_notes",
//this is the id from the deployment record for the suitelet
deploymentId: "customdeploy_suitelet_notes",
params: { recordId: recordId, recordType: recordType },
});
window.open(
suiteletURL,
"_blank",
"popup=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,top=500,left=500,width=1000,height=1000"
);
我收到以下错误消息:“org.mozilla.javascript.EcmaError:ReferenceError:未定义“window”。
我在网上找不到任何关于如何定义 'window'(即当前的 window)的信息。
或者,我正在考虑添加一个在提交时自动关闭 window 的 onclick 事件。我似乎无法找到任何关于我将如何去做的事情(使用哪些 API)或者这是否可能?
所以我的问题是:
- 如何在服务器端脚本中定义 'window'?
- 如果套件上的提交按钮是使用
添加的
form.addSubmitButton({label:submit})
是否可以为提交按钮添加一个功能,以便除了保存记录。 window 可以在指定的秒数后关闭吗? (即添加 setTimeout 方法?)
我是否需要自定义按钮而不是 form.addSubmit 按钮来实现此目的?
我尝试了各种方法,但我并不喜欢,因为我什至不确定这些是否可行。
编辑:我已经尝试在 pageinit 上使用 window.close 函数创建一个新的客户端脚本,并将此客户端脚本附加到下面的 suitelet 响应中
/** *@NApiVersion 2.x
* *@NScriptType Suitelet
* */
define(["N/ui/serverWidget", "N/log", "N/record", "N/url"], function (
serverWidget,
log,
record,
url
) {
/** * @param {SuiteletContext.onRequest} context */
function onRequest(context) {
if (context.request.method === "GET") {
var invoice_id = parseInt(context.request.parameters.recordId);
var form = serverWidget.createForm({ id: "notes", title: "Notes" });
var customerGroup = form.addFieldGroup({
id: "customerDetails",
label: "Customer Details",
});
customerGroup.isSingleColumn = false;
form.addSubmitButton({ label: "Submit" });
var select = form.addField({
id: "custpage_source",
type: serverWidget.FieldType.SELECT,
label: "Source of Communication",
container: "customerDetails",
});
select.addSelectOption({ value: 1, text: "Phone" });
select.addSelectOption({ value: 2, text: "Email" });
select.addSelectOption({ value: 3, text: "Website Contact Form" });
select.addSelectOption({ value: 4, text: "Other" });
form.addPageLink({
type: serverWidget.FormPageLinkType.CROSSLINK,
title: "Invoice",
url:
"https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
invoice_id,
});
var parentTransaction = form.addField({
id: "custpage_parent_transaction",
type: serverWidget.FieldType.SELECT,
label: "Parent Transaction",
container: "customerDetails",
});
parentTransaction.addSelectOption({
value: invoice_id,
text: invoice_id,
});
context.response.writePage(form);
function getBaseUrl() {
return url.resolveRecord({ recordType: record.Type.INVOICE });
}
} else {
var delimiter = /\u0001/;
var sourceField = context.request.parameters.custpage_source;
var parentField = context.request.parameters.custpage_parent_transaction;
var invoiceRecord = record.load({
type: record.Type.INVOICE,
id: parentField,
});
log.debug("parent record", invoiceRecord);
var recObj = record.create({ type: "customrecord_user_notes" });
recObj.setValue({ fieldId: "custrecord_source", value: sourceField });
recObj.setValue({
fieldId: "custrecord_parent_transaction",
value: parentField,
});
var userNote = recObj.save({});
var notesFieldUpdate = record.submitFields({
type: record.Type.INVOICE,
id: parentField,
values: {
custbody_notes_check:
"<span style='color:#e74c3c;'>Check Notes</span>",
},
});
log.debug("notesfield", notesFieldUpdate);
// context.response.write("Note Created");
var form_close = serverWidget.createForm({ id: "notes_close", title: "Notes" });
form_close.clientScriptFileId = 2637;
context.response.writePage(form_close)
}
}
return { onRequest: onRequest };
});
提交时正在创建 form_close 页面,但未触发客户端脚本函数
这是客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define([], function () {
/**
* @param {ClientScriptContext.pageInit} context
*/
function pageInit(context) {
alert("client script pageinit triggered")
window.close();
}
return {
pageInit: pageInit,
};
});
我是否遗漏了客户端脚本中的某些内容?
我无法让客户端脚本触发 suitelet 的 post 响应。
相反,我发现这是在提交 suitelet
后关闭 window 的唯一方法
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/ui/serverWidget", "N/log", "N/record", "N/url"], function (
serverWidget,
log,
record,
url
) {
/**
* @param {SuiteletContext.onRequest} context
*/
function onRequest(context) {
if (context.request.method === "GET") {
// Section One - Forms
var invoice_id = parseInt(context.request.parameters.recordId);
var form = serverWidget.createForm({
id: "notes",
title: "Notes",
});
//form.clientScriptFileId=5110;
var customerGroup = form.addFieldGroup({
id: "customerDetails",
label: "Customer Details",
});
customerGroup.isSingleColumn = false;
form.addSubmitButton({
label: "Submit",
});
var select = form.addField({
id: "custpage_source",
type: serverWidget.FieldType.SELECT,
label: "Source of Communication",
container: "customerDetails",
});
//the value is the internal id of the option under customisation>lists,records and forms>lists>'source of communication' list
select.addSelectOption({
value: 1,
text: "Phone",
});
select.addSelectOption({
value: 2,
text: "Email",
});
select.addSelectOption({
value: 3,
text: "Website Contact Form",
});
select.addSelectOption({
value: 4,
text: "Other",
});
form.addPageLink({
type: serverWidget.FormPageLinkType.CROSSLINK,
title: "Invoice",
url:
"https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
invoice_id,
});
var parentTransaction = form.addField({
id: "custpage_parent_transaction",
type: serverWidget.FieldType.SELECT,
label: "Parent Transaction",
container: "customerDetails",
});
parentTransaction.addSelectOption({
value: invoice_id,
text: invoice_id,
});
// form.updateDefaultValues({
// custpage_recordurl:
// "https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
// recId,
// });
context.response.writePage(form);
function getBaseUrl() {
return url.resolveRecord({
recordType: record.Type.INVOICE,
});
}
// Section Two - Tabs - See "Steps for Adding a Tab to a Form"
// Section Three - Sublist - See "Steps for Adding a Sublist to a Form"
} else {
// Section Four - Output - Used in all sections
var delimiter = /\u0001/;
var sourceField = context.request.parameters.custpage_source;
var parentField = context.request.parameters.custpage_parent_transaction;
var invoiceRecord = record.load({
type: record.Type.INVOICE,
id: parentField,
});
log.debug("parent record", invoiceRecord);
// context.response.write(
// "You have entered:" + "<br/> Name: " + sourceField
// );
var recObj = record.create({
type: "customrecord_user_notes",
});
recObj.setValue({ fieldId: "custrecord_source", value: sourceField });
recObj.setValue({
fieldId: "custrecord_parent_transaction",
value: parentField,
});
var userNote = recObj.save({});
var notesFieldUpdate = record.submitFields({
type: record.Type.INVOICE,
id: parentField,
values: {
custbody_notes_check:
"<span style='color:#e74c3c;'>Check Notes</span>",
},
});
log.debug("notesfield", notesFieldUpdate);
// context.response.write((location, "_self").close());
context.response.write("Note Created");
context.response.write("<script>window.close();</script>");
// var close_form = serverWidget.createForm({
// id: "close_form",
// title: "close form",
// });
// close_form.clientScriptFileId = 2637;
// context.response.writePage(close_form);
}
}
return {
onRequest: onRequest,
};
});
我正在尝试在 suitelet 上使用 window.close() 作为 post 响应的一部分。
suitelet 是从客户端脚本打开的弹出窗口。
这是客户端脚本的相关部分:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/url", "N/currentRecord"], function (
record,
url,
currentRecord
) {
/**
* @param {ClientScriptContext.pageInit} context
* @param {ClientScriptContext.onclick_callforSuitelet} context
*/
function pageInit() {}
function onclick_callforSuitelet() {
var record = currentRecord.get();
var recordId = record.id;
var recordType = record.type;
log.debug("recId", recordId);
log.debug("recType", recordType);
//this is the script id on the script record for the suitelet (not the deployment)
var suiteletURL = url.resolveScript({
scriptId: "customscript_suitelet_notes",
//this is the id from the deployment record for the suitelet
deploymentId: "customdeploy_suitelet_notes",
params: { recordId: recordId, recordType: recordType },
});
window.open(
suiteletURL,
"_blank",
"popup=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,top=500,left=500,width=1000,height=1000"
);
我收到以下错误消息:“org.mozilla.javascript.EcmaError:ReferenceError:未定义“window”。
我在网上找不到任何关于如何定义 'window'(即当前的 window)的信息。
或者,我正在考虑添加一个在提交时自动关闭 window 的 onclick 事件。我似乎无法找到任何关于我将如何去做的事情(使用哪些 API)或者这是否可能?
所以我的问题是:
- 如何在服务器端脚本中定义 'window'?
- 如果套件上的提交按钮是使用 添加的
form.addSubmitButton({label:submit})
是否可以为提交按钮添加一个功能,以便除了保存记录。 window 可以在指定的秒数后关闭吗? (即添加 setTimeout 方法?)
我是否需要自定义按钮而不是 form.addSubmit 按钮来实现此目的?
我尝试了各种方法,但我并不喜欢,因为我什至不确定这些是否可行。
编辑:我已经尝试在 pageinit 上使用 window.close 函数创建一个新的客户端脚本,并将此客户端脚本附加到下面的 suitelet 响应中
/** *@NApiVersion 2.x
* *@NScriptType Suitelet
* */
define(["N/ui/serverWidget", "N/log", "N/record", "N/url"], function (
serverWidget,
log,
record,
url
) {
/** * @param {SuiteletContext.onRequest} context */
function onRequest(context) {
if (context.request.method === "GET") {
var invoice_id = parseInt(context.request.parameters.recordId);
var form = serverWidget.createForm({ id: "notes", title: "Notes" });
var customerGroup = form.addFieldGroup({
id: "customerDetails",
label: "Customer Details",
});
customerGroup.isSingleColumn = false;
form.addSubmitButton({ label: "Submit" });
var select = form.addField({
id: "custpage_source",
type: serverWidget.FieldType.SELECT,
label: "Source of Communication",
container: "customerDetails",
});
select.addSelectOption({ value: 1, text: "Phone" });
select.addSelectOption({ value: 2, text: "Email" });
select.addSelectOption({ value: 3, text: "Website Contact Form" });
select.addSelectOption({ value: 4, text: "Other" });
form.addPageLink({
type: serverWidget.FormPageLinkType.CROSSLINK,
title: "Invoice",
url:
"https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
invoice_id,
});
var parentTransaction = form.addField({
id: "custpage_parent_transaction",
type: serverWidget.FieldType.SELECT,
label: "Parent Transaction",
container: "customerDetails",
});
parentTransaction.addSelectOption({
value: invoice_id,
text: invoice_id,
});
context.response.writePage(form);
function getBaseUrl() {
return url.resolveRecord({ recordType: record.Type.INVOICE });
}
} else {
var delimiter = /\u0001/;
var sourceField = context.request.parameters.custpage_source;
var parentField = context.request.parameters.custpage_parent_transaction;
var invoiceRecord = record.load({
type: record.Type.INVOICE,
id: parentField,
});
log.debug("parent record", invoiceRecord);
var recObj = record.create({ type: "customrecord_user_notes" });
recObj.setValue({ fieldId: "custrecord_source", value: sourceField });
recObj.setValue({
fieldId: "custrecord_parent_transaction",
value: parentField,
});
var userNote = recObj.save({});
var notesFieldUpdate = record.submitFields({
type: record.Type.INVOICE,
id: parentField,
values: {
custbody_notes_check:
"<span style='color:#e74c3c;'>Check Notes</span>",
},
});
log.debug("notesfield", notesFieldUpdate);
// context.response.write("Note Created");
var form_close = serverWidget.createForm({ id: "notes_close", title: "Notes" });
form_close.clientScriptFileId = 2637;
context.response.writePage(form_close)
}
}
return { onRequest: onRequest };
});
提交时正在创建 form_close 页面,但未触发客户端脚本函数
这是客户端脚本:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define([], function () {
/**
* @param {ClientScriptContext.pageInit} context
*/
function pageInit(context) {
alert("client script pageinit triggered")
window.close();
}
return {
pageInit: pageInit,
};
});
我是否遗漏了客户端脚本中的某些内容?
我无法让客户端脚本触发 suitelet 的 post 响应。
相反,我发现这是在提交 suitelet
后关闭 window 的唯一方法
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(["N/ui/serverWidget", "N/log", "N/record", "N/url"], function (
serverWidget,
log,
record,
url
) {
/**
* @param {SuiteletContext.onRequest} context
*/
function onRequest(context) {
if (context.request.method === "GET") {
// Section One - Forms
var invoice_id = parseInt(context.request.parameters.recordId);
var form = serverWidget.createForm({
id: "notes",
title: "Notes",
});
//form.clientScriptFileId=5110;
var customerGroup = form.addFieldGroup({
id: "customerDetails",
label: "Customer Details",
});
customerGroup.isSingleColumn = false;
form.addSubmitButton({
label: "Submit",
});
var select = form.addField({
id: "custpage_source",
type: serverWidget.FieldType.SELECT,
label: "Source of Communication",
container: "customerDetails",
});
//the value is the internal id of the option under customisation>lists,records and forms>lists>'source of communication' list
select.addSelectOption({
value: 1,
text: "Phone",
});
select.addSelectOption({
value: 2,
text: "Email",
});
select.addSelectOption({
value: 3,
text: "Website Contact Form",
});
select.addSelectOption({
value: 4,
text: "Other",
});
form.addPageLink({
type: serverWidget.FormPageLinkType.CROSSLINK,
title: "Invoice",
url:
"https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
invoice_id,
});
var parentTransaction = form.addField({
id: "custpage_parent_transaction",
type: serverWidget.FieldType.SELECT,
label: "Parent Transaction",
container: "customerDetails",
});
parentTransaction.addSelectOption({
value: invoice_id,
text: invoice_id,
});
// form.updateDefaultValues({
// custpage_recordurl:
// "https://<accountid>.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=" +
// recId,
// });
context.response.writePage(form);
function getBaseUrl() {
return url.resolveRecord({
recordType: record.Type.INVOICE,
});
}
// Section Two - Tabs - See "Steps for Adding a Tab to a Form"
// Section Three - Sublist - See "Steps for Adding a Sublist to a Form"
} else {
// Section Four - Output - Used in all sections
var delimiter = /\u0001/;
var sourceField = context.request.parameters.custpage_source;
var parentField = context.request.parameters.custpage_parent_transaction;
var invoiceRecord = record.load({
type: record.Type.INVOICE,
id: parentField,
});
log.debug("parent record", invoiceRecord);
// context.response.write(
// "You have entered:" + "<br/> Name: " + sourceField
// );
var recObj = record.create({
type: "customrecord_user_notes",
});
recObj.setValue({ fieldId: "custrecord_source", value: sourceField });
recObj.setValue({
fieldId: "custrecord_parent_transaction",
value: parentField,
});
var userNote = recObj.save({});
var notesFieldUpdate = record.submitFields({
type: record.Type.INVOICE,
id: parentField,
values: {
custbody_notes_check:
"<span style='color:#e74c3c;'>Check Notes</span>",
},
});
log.debug("notesfield", notesFieldUpdate);
// context.response.write((location, "_self").close());
context.response.write("Note Created");
context.response.write("<script>window.close();</script>");
// var close_form = serverWidget.createForm({
// id: "close_form",
// title: "close form",
// });
// close_form.clientScriptFileId = 2637;
// context.response.writePage(close_form);
}
}
return {
onRequest: onRequest,
};
});