Custom Record: Use require() in client side Message window – CodeMirror errors

I’m trying to set the Subject of an Email Message being generated from a Custom Record (using the “Email” button in the UI) dynamically.  To do this, I have a UserEvent script that creates an inlineHTML field, with JS as the text like so:


id : 'custpage_page_load_js',

type : serverWidget.FieldType.INLINEHTML,

label : 'PageLoadJS'

}).defaultValue = '<script>require([\'/SuiteScripts/path_to_my_client_script'], function(c) { c.afterPageLoad(); });</script>';

My afterPageLoad() function does the work of determining what the subject should be, and setting it via


The problem I’m having is that the above breaks the HTML message editor. I believe it’s something to do with calling a script using require(). I tested without the UserEvent, simply calling my require in the browser console e.g. require([‘/SuiteScripts/path_to_my_client_script’], function(c) { c.afterPageLoad(); });

This works as above. What I notice is that if I click the “DIV” button on the message editor BEFORE I run the require in the console, the Message Editor is fine (and continues to work even after running my test). However, if I run my test in the console prior to clicking the DIV button at least once, I get the errors.

I don’t know a lot about require(). Is there some issue with it overriding what’s been required if I call it manually before anything else happens?

Custom Record: Use require() in client side Message window - CodeMirror errors

Beginner Asked on October 15, 2019 in SuiteScript.

How do you have a button to email? Is it it native?

on October 15, 2019.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor