Vernita
04/25/2022, 8:47 AM/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/url"], function (url) {
/**
* @param {ClientScriptContext.pageInit} context
*/
function pageInit(context) {
var window = document.location();
log.debug("window", window);
window.close();
}
return {
pageInit: pageInit,
};
});
I am not sure how to define 'window' as a variable so it is referring to the current window (the focused browser window) at the time the function is called
i.e. I want the suitelet to trigger the client script and the client script to close the suitelet window.
Thanksbattk
04/25/2022, 9:28 AMbattk
04/25/2022, 9:28 AMbattk
04/25/2022, 9:31 AMbattk
04/25/2022, 9:31 AMbattk
04/25/2022, 9:31 AMbattk
04/25/2022, 9:32 AMbattk
04/25/2022, 9:32 AMbattk
04/25/2022, 9:34 AMZoran R-DATAGRAM
04/25/2022, 9:35 AMZoran R-DATAGRAM
04/25/2022, 9:40 AMVernita
04/25/2022, 11:50 PM/**
*@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://tstdrv.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://tstdrv.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");
pageInit
}
}
return {
onRequest: onRequest,
};
});
In the post response, I wasn't sure how to call the function from the client scriptVernita
04/25/2022, 11:53 PMbattk
04/26/2022, 1:18 AMbattk
04/26/2022, 1:19 AMbattk
04/26/2022, 1:20 AMbattk
04/26/2022, 1:20 AMVernita
04/26/2022, 4:49 AMVernita
04/26/2022, 4:50 AMVernita
04/26/2022, 4:51 AMbattk
04/26/2022, 5:36 AMcall itwas the client script, not the pageInit function
battk
04/26/2022, 5:37 AMVernita
04/26/2022, 6:04 AM* @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;
I was confused about this part though "call [clientscript] on your Suitelet on the post method context"
How would I call it in the post method context?
That's what my original query was around since I can't find the correct way to do thatbattk
04/26/2022, 6:11 AMbattk
04/26/2022, 6:12 AMZoran R-DATAGRAM
04/26/2022, 6:32 AMVernita
05/14/2022, 6:30 AM/** *@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>.<http://app.netsuite.com/app/accounting/transactions/custinvc.nl?id=|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 };
});
This is printing the second form from the response on submit
The functions from the client script (under pageinit) are not triggering however.
Have I called the client script in the correct way?battk
05/14/2022, 2:18 PMVernita
05/15/2022, 11:14 PM/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define([], function () {
/**
* @param {ClientScriptContext.pageInit} context
*/
function pageInit(context) {
window.close();
}
return {
pageInit: pageInit,
};
});
This is the close window client script (file id 2637 referenced in form_close.clientScriptFileId = 2637;)battk
05/15/2022, 11:22 PMbattk
05/15/2022, 11:22 PMbattk
05/15/2022, 11:22 PMbattk
05/15/2022, 11:23 PMVernita
05/16/2022, 1:21 AM