I am using SuiteScript 2.0 in NetSuite and got an error when I open an existing invoice:
Error: Load timeout for modules: N/redirect
I plan to do the followings:
Use a user event script to add a custom button on an invoice page to appear under 'view' mode. Upon clicking the button, a custom client-side script 'rs_cm_invoice_telema.js' is called and function 'onButtonClick' is executed.
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/ui/serverWidget'],
/**
* @param {serverWidget} serverWidget
*/
function(serverWidget) {
/**
* Defines the function definition that is executed before record is loaded.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @param {Form} scriptContext.form - Current form
* @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
* @since 2015.2
*/
function beforeLoad(context) {
var invoiceForm = context.form;
// Set the module path to the custom client-side script
invoiceForm.clientScriptModulePath = './rs_cm_invoice_telema.js';
// Add a custom button to an invoice under 'view' mode
invoiceForm.addButton({
id : 'custpage_export_invoice_to_telema_button',
label : 'Export to Telema',
functionName : 'onButtonClick'
});
}
return {beforeLoad : beforeLoad}
});
This custom client-side module calls another user event script using 'redirect' module. This is where the error occurs.
/**
* @NApiVersion 2.0
*/
define(['N/log', 'N/redirect'],
/**
* @param {log} log
* @param {redirect} redirect
*/
function(log, redirect) {
function callUserEventScript() {
redirect.toSuitelet({
scriptId : '216', // '<your-script-id>'
deploymentId : '307', // '<your-deployment-id>'
});
}
return {onButtonClick: callUserEventScript}
});
The user event script that the custom module above is supposed to call doesn't have 'N'/redirect' module. The codes there are quite long, so I won't include them here unless it is needed.
I use Microsoft Edge and Edge didn't have a problem with runtime error from loading 'N/redirect' module at the beginning. I started facing this issue after a while.
Any help would be appreciated. Let me know if you need additional information. Thank you.
I have tried the followings:
I was expecting 'N/redirect' to load and call a user event script.
I realized that 'N/redirect' module is for a server-side script. I was using it in the client-side script, hence the error.
Solution from SuiteAnswers can be found here https://suiteanswers.custhelp.com/app/answers/detail/a_id/12239/loc/en_US