I wonder if it’s because my custom module has an `...
# suitescript
a
I wonder if it’s because my custom module has an
NApiVersion
of 2.x
d
potentially, the custom module in the example I was referencing didn't have any tags at the top
a
I tried. It didn’t fix it 😞
I’ll try without arrow notation
That also didn’t work. Hmm.
r
Try absolute path?
a
Nope. That didn’t work either
Strangely, another of my Custom Modules does work, so I’m trying to figure out what’s different about this one that’s causing this error
d
I think I have actually gotten that error before in 2.0, whenever there is usage of a N/module "globally" outside of being contained in a function within the define... maybe that is the case?
e
That error happens when you have NetSuite module code executing outside of any entry point callstack.
so if you have some code outside of functions that always runs as soon as the module is loaded , e.g. some module initialization code, it cannot contain any SuiteScript module code
a
I did, but I tried changing that too to no avail
But I did find the problem.
In order to simplify my code, I added this line to the return object of my custom module:
UserID: runtime.getCurrentUser().id
which allows me to get the User ID by just typing
_Ext.UserID
instead of
runtime.getCurrentUser().id
. I do this for a number of things and it’s purely a quality-of-life improvement. The error is stating that my
runtime
module isn’t available when it’s creating the return object.
e
Right, because the
return
of a module is outside any entry point callstack
a
Which is interesting, because it works beautifully in 2.0
It makes me a little sad, but what can you do…
e
Perhaps the 2.1 analyzer has been updated
yeah ¯\_(ツ)_/¯
j
So is this an example of code that works in 2.0 but does not work in 2.1, and will break once NetSuite decides to upgrade 2.x to 2.1?
To be fair, since
All SuiteScript API Modules are unavailable while executing your define callback
, it probably shouldn't have worked in 2.0 either
e
Given that it's 2.1, you could probably accomplish this by making the property a getter
That way
runtime
wouldn't actually be invoked until you actually asked for the property during a script execution
so maybe
Copy code
return {
  ...,
  get UserID() { return runtime.getCurrentUser().id; }
  ...
};
a
Hmm. I haven’t tried setting a getter within the return object
e
I haven't either; that's totally untested, but it's a thought
As long as you're only referencing
Ext.UserID
from within an entry point callstack. If not, you'll still run into the same error I think
a
I will say that I did try this:
Untitled
It was unsuccessful
e
😞