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) {

try{
var warningMessage = message.create({

title: "Warning: Lorem Ipsum",

message: 'lorem ipsum . . . .',

type: message.Type.WARNING

}).show();

}catch(e){}

}

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
Best answer

Have you tried?

var myData = {foo:”bar”};
warning.defaultValue = “<script>NS.jQuery(function($){ require([‘/SuiteScripts/pathToClientScript/myClientScript’], function(a){ a.showMessage(‘” + JSON.stringify(myData) + “‘);});});</script>”;

Rookie Answered on September 16, 2019.

Stringify! Thanks, that did it. I initially tried just passing my into the showMessage function, but didn’t stringify it and then went down other paths. Thanks for the help.

 

on September 16, 2019.
Add Comment

Your Answer

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