RE: Can you pass data from a User Event script to a Client Script in SS2.x?

Hey folks!

I have a User Event script that is calling showMessage() in a Client Script. So in the User Event script, it looks something like this:


var warning = context.form.addField({
id: 'custpage_custom_id',
type: serverWidget.FieldType.INLINEHTML
warning.defaultValue = "<script>NS.jQuery(function($){ require(['/SuiteScripts/pathToClientScript/myClientScript'], function(a){ a.showMessage();});});</script>";

And the Client Script is something like this:

function showMessage(data) {

var warningMessage = message.create({

title: "Warning: Lorem Ipsum",

message: 'lorem ipsum . . . .',

type: message.Type.WARNING




I need some data, a variable, from the User Event to pass into the Client Script and be added to/concatenated into the message of the Client Script. I’ve tried a few different way, including by adding a new property to the object, but it seems SuiteScript doesn’t allow for that. I’ve also tried to get the current record in the Client Script and log it, but even when the Client Script runs (displays my warning message) the log doesn’t appear in the Execution Log in NetSuite. So perhaps a secondary question is: Is there a trick to logging in a Client Script? But really ,any insight in passing data from User Event to Client Script would be greatly appreciated!


mreser Rookie Asked on September 16, 2019 in SuiteScript.
Add Comment
4 Answers

HI! you should be able to utilise the N/cache module for passing data between UE and Client script.

Rookie Answered on September 16, 2019.

Hi Karl, thanks. How does N/cache work for a Client Script? I thought it was on server side only and when I try to inject/load N/cache into my client script I just get: Fail to evaluate script: {“type”:”error.SuiteScriptModuleLoaderError”,”name”:”MODULE_DOES_NOT_EXIST”,”message”:”Module does not exist: N/cache.js”,”stack”:[]}   I can get and put cache values in the User Event, but not sure how to grab it in the Client.   Thanks

on September 16, 2019.

The cache module is not available client side. Also the intended use of the module is to improve performance, not as a messaging mechanism between scripts. Notably, whilst you are able to specify a TTL, NetSuite makes no guarantee that the data will not be removed earlier, so even if it works 99% of the time it’s not best practice and can lead to hard to track bugs in the future.

on September 16, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.