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

As of the 2018.2 release, you can set a message to display directly in the User Event script without having to add any client side script at all:

context.form.addPageInitMessage({
  title: "Warning: Lorem Ipsum",
  message: 'lorem ipsum . . . .',
  type: message.Type.WARNING
});

https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1530198114.html

Advanced Answered on September 16, 2019.
Add Comment

Your Answer

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