This topic contains 5 replies, has 0 voices, and was last updated by chanarbon 7 years, 8 months ago.

  • Author
    Posts
  • #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.

  • #1154

    david.smith

    use the require with your define script

  • #1155

    Jarod Tavares

    That’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.

  • #1156

    david.smith

    I’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.

  • #1157

    Jarod Tavares

    By “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.

  • #1158

    chanarbon

    The 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.

You must be logged in to reply to this topic.