Boris Yasen
11/19/2024, 3:20 PMCeligo AI
11/19/2024, 3:20 PMAI generated answer (using internal Slack threads):To run a function in a client script from an inline HTML field in a Suitelet, you can use the
require
function to access SuiteScript modules. Here's a sample code snippet that was shared in the conversations:
javascript
var singleFolderFn = 'launchFolderWindow(\'' + folderId + '\')';
var singleFolderLinkText = '<a href="#" onclick="' + getClientOnclickJS(singleFolderFn) + '"> one file</a>';
function getClientOnclickJS(functionName) {
var CLIENT_SCRIPT_MODULE_PATH = '/SuiteScripts/folder/client-script-file';
var onclickBlob = "var rConfig = JSON.parse('{}');\
rConfig['context'] = '"+ CLIENT_SCRIPT_MODULE_PATH + "';\
var entryPointRequire = require.config(rConfig);\
entryPointRequire(['"+ CLIENT_SCRIPT_MODULE_PATH + "'],\
function (mod) {\
try { \
mod."+ functionName + "\
} catch(e){\
console.log(e);\
}\
}); return false;";
return onclickBlob.replace(/\s\s\s\s/gmi, '');
}
In this example, getClientOnclickJS
function is used to generate the onclick
attribute for the HTML element. This function takes the name of the function you want to call in your client script as a parameter. The onclickBlob
variable contains the code that will be executed when the HTML element is clicked. This code uses the require
function to load the client script module and call the specified function.
Please note that this approach might not be the best practice in all situations, especially on native NetSuite forms. It's more suitable for custom Suitelet pages. Also, be aware that NetSuite might change the way they handle this, which could cause your script to fail in the future.
******
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
11/19/2024, 3:20 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.877236426
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.864465833
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859345734
Celigo AI
11/19/2024, 3:20 PM