简体   繁体   中英

Getting “All SuiteScript API Modules are unavailable while executing your define callback” When Creating NetSuite Script With Custom Module

When trying to create a new script record within NetSuite, I get the error "Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback". I can't find any real information on what may cause this, and I can't see anything in my custom module that looks suspicious. I can't post the code here as the module is nearly 2,000 lines in length and has some proprietary code in it. As it was with another custom module I built that had issues at the "Upload Script File" stage, if I remove reference to the module in the script the process continues, and then I can go back to the script and return the module reference, wherein everything seems to work correctly afterward.

The only information I found that seemed useful was that the error could be caused by referencing a module outside of the define callback, but that isn't the case. The module has two large objects constructed within, and they're returned from the callback. The only other thing I can think of is that this module calls the other custom module, but I haven't seen anything that says I can't do that.

So, overall, what should I look for to resolve this error? I really cn't seem to find anything useful or that applies to this situation.

EDIT

Ok, so I believe that I discovered the cause is due to the calling of a search function outside of an object/function being returned for the callback. Here's a simplified version of what's happening, since a lot of fields and values are managed:

/** 
 * custom.module.js
 * @NApiVersion 2.x
 * @NModuleScope Public 
 */


define(['N/search'],
/**
 * @param {search} search
 */
function(search) {

    var fields = new Array("a","b","c","d","e");
    var lValues = search.lookupFields({
            type : "customrecord_ng_cs_settings"
        ,   id : "1"
        ,   columns : fields
    });
    var _values = {
            a :     lValues.a
        ,   b :     lValues.b
        ,   c :     lValues.c
        ,   d :     lValues.d
        ,   e :     lValues.e
    };
    var _funcs = {
            func_a : function() {
                // do stuff
            }
        ,   func_b : function() {
                // do stuff
            }
        ,   func_c : function() {
                // do stuff
            }
    };

    return {
            value : _values
        ,   func : _funcs
    };

});

I need to maintain this kind of structure as not everything that gets returned in _values is actually a search/lookup result. Am I going to be forced to encapsulate the construction of this object within a function? And would that cause the lookup to occur every time a value is needed? This is a conversion from a 1.0 script, and this gets loaded and set only once at the beginning so the data is all there the entire time without having to be repeatedly fetched.

So, I see the following options:

  1. Convert the callback output to a function and doing something like
    the following at the start of every script:
    var _values = customModule.values();
  1. Find some way to rework the code so that any script using the module can still access values in the following way:
    var _a = customModule.values.a;

I'd very much prefer option #2. Is it possible?

You cannot run any SuiteScript module code outside of an entry point. You will need to encapsulate your data retrieval in a function, then invoke that function at the beginning of your entry point.

If you want to avoid multiple fetches, you can leverage memoization in your function, or perhaps N/cache or N/session to store the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM