Boban Dragojlovic
05/15/2025, 5:16 PMCeligo AI
05/15/2025, 5:17 PMAI generated answer (using internal Slack threads):To load a NetSuite module dynamically, you can use the
require
function in SuiteScript. This function allows you to load a module at runtime. Here is an example of how you can use it:
javascript
function debug_require(module, in_name)
{
var script_config_json = {
"paths": {
"custom_module_1": "/path/to/module/1.js",
"custom_module_2": "/path/to/module/2.js",
}
}
var module_to_require = module;
if(script_config_json.paths[module])
{
module_to_require = script_config_json.paths[module];
}
// require the module
require([module_to_require], function(loaded)
{
// see if we provide a name
var name = in_name;
// if we don't provide a name, use the module as a name
if(!name)
{
name = module
}
// only use a name after the last '/' symbol (works for 'N/record' as well as '/Suitescript/Libraries/...')
name = name.slice(name.lastIndexOf(`/`)+1);
// only use a name before the first '.' (works for 'stuff.js')
name = name.replace(/\\..*/g,'');
// if there is a window
if(window)
{
// if the original module requested was current record, call get, and then assign that to the window object
if(module == 'N/currentRecord')
{
window[name] = loaded.get();
console.group(`window.${name} loaded`);
console.warn(`Do not use in actual scripts - only for debugging in console.`);
console.warn(`In real usage of require([${in_name}]), you will need to call currentRecord.get() after require()ing.`)
console.groupEnd(`window.${name}`);
}
// otherwise just assign it to the window
else
{
window[name] = loaded;
console.group(`window.${name} loaded`)
console.warn(`Do not use in actual scripts - only for debugging in console.`);
console.groupEnd(`window.${name}`);
}
}
})
}
This function allows you to load a module dynamically and assign it to a global variable for easy access. You can use this function in the console for debugging purposes. However, it's not recommended to use this function in actual scripts.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
05/15/2025, 5:17 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.831662357
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816899836
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.807113647
Celigo AI
05/15/2025, 5:17 PM