This topic contains 5 replies, has 0 voices, and was last updated by chanarbon 7 years, 8 months ago.
-
AuthorPosts
-
February 17, 2017 at 3:00 pm #1153
Jarod Tavares…or will I be shooting myself in the foot?
I was disappointed that N/cache is server-side only, so I thought I might build a wrapper. I have a fairly slow-running module that’s a little pokey on the server-side but it’s intolerably slow client-side, and I’d like to improve it in both without too much yak shaving in each and every caller. So a quick cache wrapper made sense. I did something similar to what was described here, but when I went back to edit the script calling the wrapper module, I was greeted with “Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback”, as has been discussed toward the end of this thread, as mentioned by ironside, which fizzled out due to the use of TypeScript.
TLDR:Can’t search for all units by internal id.
I now search for all base units, load each record, load “uom” line items per record, concat results.
Too slow, want to cache.
N/cache is server only.
Ok, then I’ll wrap the module.
Conditional module loading works as expected!
NetSuite now won’t allow editing calling module from the UI.
Any enhancement to 1, 4, or 7 would have spared me from this situation.
This is a cached copy. Click here to see the original post. -
February 17, 2017 at 3:03 pm #1154
david.smithuse the require with your define script
-
February 21, 2017 at 7:53 am #1155
Jarod TavaresThat’s what I’ve been doing.
Code:
define([‘N/runtime’, ‘require’],
function (runtime, require) {
var cache = { /* alternative implementation */ };var isServerSide = runtime.executionContext !== runtime.ContextType.USER_INTERFACE;
if (isServerSide) {
require([‘N/cache’], function (nCache) {
cache = nCache;
});
}return cache;
});
Works great, but if it prevents us from tweaking scripts in the UI, that’s a problem. -
February 21, 2017 at 8:40 am #1156
david.smithI’m not following what you’re asking then. What do you mean by tweaking scripts in the UI?
What are you wrapping? Why not just load the scripts that are needed to run when you need to run them? Cache should be used only as a temporary storage for data. It’s also limited by memory size.
-
February 22, 2017 at 10:25 am #1157
Jarod TavaresBy “tweaking scripts in the UI”, I mean logging into NetSuite and editing the script in the browser. Not necessarily a best practice, but it’s not an ability I wish to break.
I’m wrapping N/cache. If I have a library script that requires the N/cache module, I then cannot require that script in a Client Script, because N/cache is server-side only.
-
February 25, 2017 at 4:54 am #1158
chanarbonThe restrictions for the module loading whether it is a server only, client only or for server and client would still apply. The concept of conditional loading is rather related to calling a module compatible to the script type depending on the scenario without loading it before the script runtime.
-
AuthorPosts
You must be logged in to reply to this topic.