title: Getting "All SuiteScript API Modules are unavailable while executing your define callback" When Creating NetSuite Script With Custom Module
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>EDIT</p>
  
  <p>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:</p>
  
  <pre><code>/** 
   * 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
      };
  
  });
  </code></pre>
  
  <p>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.</p>
  
  <p>So, I see the following options:</p>
  
  <ol>
  <li>Convert the callback output to a function and doing something like<br>
  the following at the start of every script:</li>
  </ol>
  
  <pre><code>    var _values = customModule.values();
  </code></pre>
  
  <ol start="2">
  <li>Find some way to rework the code so that any script using the module
  can still access values in the following way:</li>
  </ol>
  
  <pre><code>    var _a = customModule.values.a;
  </code></pre>
  
  <p>I'd very much prefer option #2. Is it possible?</p>