I am trying to update the values on a custom record based on the button clicked on a suitelet
This will have 3 or 4 different buttons.
There is only one set up page that can be loaded on click of the button.
For example, 'recurring' is clicked on the suitelet. This will load a custom record page and set the parameters. If 'fortnightly invoice' button is clicked, this will also load the same custom record page and set the parameters.
Where I am getting stuck: I have a suitelet with the buttons that are designed to load the custom record by calling a client script function
Instead, as soon as the suitelet loads, the custom record page loads and is stuck in an infinite loop reloading again and again
This is my suitelet script:
/**
*@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;
});
This is the client script:
/**
*@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,
};
});
Do I need to use another script type to set the values on the custom record? (i.e not a client script)
How would I link a userevent script to the suitelet so that it is triggered on button click?
Why would the client script be automatically initiated on loading the suitelet page if it is supposed to be tied to a button on the form?
Thanks