Ah, I think I follow. Is there a supported way to ...
# suitescript
m
Ah, I think I follow. Is there a supported way to do that will work with context.form.clientScriptModulePath or do I need to resort to my backup plan of creating hidden fields with script code in them (or something of the sort)?
b
how are you creating your link element on the page?
are you using an inline html field? are you adding an inline html field using a user event?
are you using the native link field?
m
I haven't actually added the link yet in the 2.0 script - I was trying to make sure the function was available via the console first - but in the 1.0 version that works I'm adding a text field in the UE. I'm planning on going that route in the 2.0 script once I get to that point.
b
you can use @erictgrubaugh's suggestion of making the function global
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define([], function() {
  function pageInitTest(context) {
    console.log("Start page init");
  }
  window.testFunction = function(options) {
    console.log("Start test function");
  };
  return {
    pageInit: pageInitTest
  };
});
m
Ah, cool, I didn't think to try to modify
window
within the define. I assume I could use any modules loaded in the define within that function without issue?
Shoot, it doesn't look like that'll work - when I try to update the script file, NetSuite's throwing the following error:
Fail to evaluate script: org.mozilla.javascript.EcmaError: ReferenceError: "window" is not defined.
b
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
require([], function() {
  function pageInitTest(context) {
    console.log("Start page init");
  }
  (function() {
    this.testFunction = function(options) {
      console.log("Start test function");
    };
  })();
  return {
    pageInit: pageInitTest
  };
});
as an alternative, you can do what i suggest and select the element using javascript and set the onclick
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

define([], function() {
  function pageInitTest(context) {
    console.log("Start page init");
  }
  if (document) {
    document.getElementById("whateverIdYouGiveToYourAnchor").onclick = function(
      options
    ) {
      console.log("Start test function");
    };
  }

  return {
    pageInit: pageInitTest
  };
});
m
Oh interesting, I'll give both of those a shot. They both feel a bit DOM-hacky to me though, how much do you think either approach would be considered officially supported?
b
you added your own link anchor to the dom
only touch that and nothing netsuite will break
m
Makes sense. Thanks so much for your help!