Hi There
i have a suitelet with a button that redirects to a custom record and sets the field values on the custom record.
The intention is, that depending on which button is clicked on the suitelet, the values set on the custom record will change.
This is the page that is loaded when any of the buttons are clicked
The values are being set as expected on this custom record page using a client script.
However, what I am trying to do is:
- reload the custom record page once the values are set and the page is saved (where the page is then reloaded in 'view' mode)
- Have a confirmation pop up after the record is saved but before the page is reloaded
- Redirect back to the suitelet
I am stuck on the save record part of the script. The record appears to be saving changes once the fields are populated. However, the page is not reloading despite the window.location.reload part of the script.
I have tried variations of this by making it part of a separate function though haven't had any joy in getting the page to reload or to redirect back to the suitelet
Where am I going wrong in the script and what do I need to do to fix it?
The scripts are as follows:
Suitelet:
/**
*@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: "executeRecurring",
});
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;
});
Client script
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record", "N/runtime", "N/url"], function (
record,
runtime,
url
) {
/**
* @param {ClientScriptContext.pageInit} context
*/
function executeRecurring(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);
//Add additional code
window.location.href = url;
var objRecord = record.load({
type: "customrecord_nsts_ci_setup",
id: 1,
isDynamic: true,
});
//INVOICE SUMMARY SAVED SEARCH *
objRecord.setValue({
fieldId: "custrecord_nsts_ci_search",
value: 456,
});
//INVOICE DETAILS SAVED SEARCH
objRecord.setValue({
fieldId: "custrecord_nsts_ci_search_dtl",
value: 452,
});
//DEFAULT CI LAYOUT *
objRecord.setValue({
fieldId: "custrecord_nsts_ci_layout",
value: 1,
});
objRecord.save({
enableSourcing: true,
ignoreMandatoryFields: false,
});
}
function saveRecord(context) {
window.location.assign(
"https://tstdrv.app.netsuite.com/app/site/hosting/scriptlet.nl?script=313&deploy=1&compid=TSTDRV2531816&whence="
);
return true;
}
function pageInit(context) {
}
return {
pageInit: pageInit,
executeRecurring: executeRecurring,
saveRecord: saveRecord,
};
});