Sim Greenbaum
06/05/2024, 5:24 PMerictgrubaugh
06/05/2024, 5:41 PMMichael Pope
06/05/2024, 5:43 PMMichael Pope
06/05/2024, 5:45 PM// This is a helper function that I use while I am testing. It is not in the helper module becuase it cannot be added to window from there
// The main purpose of it is to open console and quickly require a module and give it an obvious name. Do not use it in actual scripts.
// examples:
// debug_require('N/currentRecord') => use window.currentRecord
// debug_require('N/email', 'customName') => use window.customName
// debug_require('/Suitescripts/.../myScript.js') => use window.myScript
// debug_require('script_config_name') => use a script defined in script_config_json
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}`);
}
}
})
}
Michael Pope
06/05/2024, 5:46 PMN/currrentRecord
, this call .get() and returns the currentRecord object automatically for you. This is because when you grab N/currentRecord
you pretty much always want to call .get()
and then do other things from there. And it's a pain to always have to call .get()
.Michael Pope
06/05/2024, 5:51 PMMichael Pope
06/05/2024, 5:52 PMnlapiSetLineItemValue()
). If you think you might need to do this in client scripts, you might need to call Suitescript 1 methods from your Suitescript 2 scripts. Kinda stinks 😕.