Anyone not able to edit scripts today? Getting thi...
# suitescript
k
Anyone not able to edit scripts today? Getting this error message which means nothing to me - this is happening even when editing the record without making any changes
Copy code
Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback.
a
I’ve gotten that error. The cause for me was that I had properties in my
return
object that were directly referencing a module. For example
return { userId: runtime.getCurrentUser().id }
. That was only an issue when editing SuiteScript 2.1 scripts, though. It doesn’t give the error in SS2.0
b
usually means you have a code using netsute's api outside of the define function
log.debug("i", "shouldn't be here"); define(["N/record"], function(record) {});
k
Thanks. About to wring that developer's neck...
So it would be something in this section
Copy code
/**
 * @author FrustratingDeveloper 
 * @date 10/24/2019
 * @description
 * @NApiVersion 2.0
 * @NScriptType MapReduceScript
 * @NModuleScope SameAccount
 * @NAmdConfig /SuiteScripts/RSM/Library/RSM_AmdConf.json
 */
define(['NB', 'RSM_CR13', 'N/search', 'N/record', 'N/runtime', 'N/error', 'N/task'],
    function ( NB, RSM, search, record, runtime, error, task) {

        /**
         * Marks the beginning of the Map/Reduce process and generates input data.
         *
         * @typedef {Object} ObjectRef
         * @property {number} id - Internal ID of the record instance
         * @property {string} type - Record type id
         *
         * @return {Array|Object|Search|RecordRef} inputSummary
         * @since 2015.1
         */
Right?
c
i've seen this happen just as a pre-processor error on netsuite's side where my code is 100% valid but they have a bug w/ their pre-processor that doesn't allow the script to be uploaded
💯 1
when creating a deployment
had to upload a very basic version w/ entry points then create the record/deployments and then upload
b
what you shared looks innocent so far
your developer also looks above average and writes nice comments
actually i take that back, that looks generic
k
That's generic
I'd share the code - but it's 1300 lines and has some proprietary info from the client included that I don't think I can share.
however - what I was looking to validate - is that any function that is used in the map/reduce must be defined in the define section there correct?
The script works in one sandbox account - but isn't working in another because it's hard coded to a particular form. and I can't update that form because I can't edit the script >.<
j
look for code that is executed outside of
getInputData
,
map
,
reduce
, or
summarize
that makes use of any member, even non-callable members of
N/xxx
modules
this includes code that is in the custom modules
'NB', 'RSM_CR13'
a
All functions should be within
define
, yes, including ones that aren’t added to the return object.
b
Copy code
/**
 *@NApiVersion 2.0
 *@NScriptType Suitelet
 */
function imValid() {
  log.debug("i will work", "but am really weird");
}
define([], function() {
  return {
    onRequest: function() {
      imValid();
    }
  };
});
doesn't have to be in the define to work
but is weird if not
k
Thanks everyone for the input
j
for example
Copy code
define(["N/record"], function(record) {
  var someTypes = {
    // accessing record.Type is invalid because it accessed while the someTypes object is initialzied, outside the callstack of getInputData
    salesorder: record.Type.SALES_ORDER
  };
  function getInputData() {
    // accessing record.load and record.Type are valid because they are accessed within the callstack of getInputData
    record.load({
      type: record.Type.SALES_ORDER,
      id: ...
    });
  }
  ...
});
k
Over my head - but passing along to the developer who's troubleshooting the other's code...
I'm guessing they were able to put their code in and have it work because they were using an IDE to push it into NetSuite.
b
@jkabot are you sure?
this should be valid
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType MapReduceScript
 */
define(["N/record"], function(record) {
  var someTypes = {
    salesorder: record.Type.SALES_ORDER
  };

  function getInputData() {
    return [someTypes];
  }

  function map(context) {
    log.debug("i should be salesorder", context.value);
  }

  return {
    getInputData: getInputData,
    map: map
  };
});
j
I believe that code should trip the error message since it is accessing a part of the N/record module (record.Type) while running the define callback.
b
message has been deleted
j
Whether or not it causes the error every time... well that's up to NetSuite
b
to my knowledge, using the closure works perfectly fine
j
I've written code like that, using record.Type outside of an entry point, that caused the error. In my case I had to change it
As far as I understand, it's an error that NetSuite mostly checks for when you upload new scripts, which is why @creece was able to get around a false positive by uploading an empty script and then editing
c
yeah its only on new script instances
k
It's definitely checking it while editing the script file from the script record
I'm sure I could have edited the file directly.
c
interesting do you get the same error if you upload it through the IDE?
k
No
in fact that's how I had them fix it so I could keep going with my testing
c
interesting
k
I'm gonna have them continue to resolve the error - but at least I can validate that the rest of the code works...
c
i know the backend does SOME checking while uploading but mainly for an entry point existing and syntax
k
It is a script that utilizes some centralized "helper" functions as the primary developer I've got working on it likes to refer to it. I'm guessing there's something slightly off about how they structured that library.
b
is this your dude
k
Yeah, he's the one helping me
not the one who wrote it initially
I told him he'd need to include more information in order to get more effective help... and I've relayed everything you have here
Random question - does the order* of the define matter?
b
Copy code
define(['NB', 'RSM_CR13', 'N/search', 'N/record', 'N/runtime', 'N/error', 'N/task'],
    function ( NB, RSM, search, record, runtime, error, task)
the module named NB goes in the NB variable
the module named RSM_CR13 goes in RSM
and so on
k
Right - but if 'NB' utilizes N/seach - do I need to have them do N/Search first?
b
no
the module named NB has its own define
s
I have seen the same behavior as @creece when creating (or editing) a script in the UI. It's a bug and NS even filed a defect for it IIRC. I have noticed this error happening less frequently lately so I think they must have changed something. It was very reliable to reproduce previously.