I have this simple User Event script: ```/** * @N...
# suitescript
m
I have this simple User Event script:
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */

define(["N/runtime", "N/log"], function (
  log,
  runtime
) {
  function afterSubmit(context) {
    log.audit("accountID", runtime.accountId);
  }

  return {
    afterSubmit: afterSubmit,
  };
});
And somehow it gives this error message when I try to save the record:
Copy code
org.mozilla.javascript.EcmaError: TypeError: Cannot find function audit in object runtime.Runtime. (/SuiteScripts/UE-Shipments.js#11)
a
You have to switch the log and the runtime in the callback.
/** * @NApiVersion 2.0 * @NScriptType UserEventScript */ define(["N/runtime", "N/log"], function (
runtime
,
log
) { function afterSubmit(context) { log.audit("accountID", runtime.accountId); } return { afterSubmit: afterSubmit, }; });
m
The order matters 😮
I didn't know that, thanks.
a
Yes; very much. The name ironically doesn't. Try: /** * @NApiVersion 2.0 * @NScriptType UserEventScript */ define(["N/runtime", "N/log"], function ( runtime,
balls
) { function afterSubmit(context) {
balls
.audit("accountID", runtime.accountId); } return { afterSubmit: afterSubmit, }; });
m
Got it, I thought SuiteScript inject the dependencies based on the name. Tried it and it worked. Thanks.
b
you can use alternative CommonJS syntax instead
m
hmm, nice
s
Also, N/log is provided for free. I am not aware of any case where it's not automatically available to you without importing it.
a
Really? I can use log.debug even without specifying it in the imports?
That might explain why I lose intellisense in my ide.
s
That's right