I have a Map/Reduce script that just stopped worki...
# suitescript
w
I have a Map/Reduce script that just stopped working with the following message: All SuiteScript API Modules are unavailable while executing your define callback. I have not made any changes to this script, and it worked last week. The script does reference another script in the define that loads N/file and N/search. I think this is where the problem is, but I'm not sure how to fix it.
k
Can you supply your code?
w
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType MapReduceScript
 * @NModuleScope SameAccount
 *
 * 1.1      Record Fields
 */
define(['N/email', 'N/record', 'N/error', 'N/runtime', 'N/format', './common/fileApiService.js'],

	function(email, record, error, runtime, format, fileApi) {
Copy code
/**
 *  Helper functions for CSV import tool
 */

define([
        "N/file",
        "N/search"
    ],
    function (
        file,
        search
    )
    {
The first block is the map/reduce and the second is the helper file fileApiService.js
k
I would try adding the below into your custom module.
Copy code
/**
 * @NApiVersion 2.0
 */
not sure if it would make a difference but i always use it lo
lol
w
lol ok this DID work last week
k
you never know?! 🤣
w
trying now
k
The only thing i would suggest is check your code just incase you have an extra brace somehwere
that is when i usually get that error
w
like I said, no changes have been made to the code
k
odd
Are you able to PM me the qhole code and i can have a look over it?
w
yes thanks
The whole point of this script is to overcome the limitations of item import via CSV, as we have many custom forms on our item record and the CSV tool requires us to break our CSV's into chunks based on the form for that particular item. A real pain when you have a price change on a brand/mfr that sells many different products that we classify differently and use different forms.
k
yeah thats a pain.
just having a look through now.
w
My feeling is that NetSuite should make the CSV tool not overwrite the form, like a checkbox or something
k
just out of interest why are you not just passing the csv straight to the getInputPhase?
if you pass a csvfile it will just intereate over every row
w
Instead of parsing into JSON?
k
yup
w
What about the headers?
k
you skip that in map
if context.key === 0 return etc.
w
Yeah but the headers are needed to know what the fields are
k
true. do the headers change or always the same
w
change all the time
k
rubbish lol
w
lol
k
TBFi would always use the map to sort the csv data then do what i need to do in reduce but thats just me.
if it works then great
w
lol yeah
I don't really consider myself a developer, just a NetSuite admin that needs to get things done
k
yeah i get that. i started there 7 years ago. now working for a partner as dev
w
nice
just forgive my sloppy code 🙂 I never have time to refine anything I write
k
its all good
s
That error usually shows up when uploading the file to the file cabinet (even if unchanged) or deploying using something like SDF. Did you do either (even if not changing the code)?
Basically, 2021.1 introduced more strict (erroneous, IMHO) validation on script files - even some that were working fine.
k
I have been unable to find a problem with the code. so @stalbert is probably correct.
s
this problem could arise via the main script file or indirectly via any library scripts.
w
I was executing the script deployment
Actually, I was executing from the script record, and that was the issue.
When I went ot the deployment itself, it works.
UGH
k
oh thats interesting
w
yeah weird
k
typical
w
sorry to waste your time
k
its all good
s
it does suggest that if you do ever edit that code, you're going to face other changes to workaround that error 😕
w
you may be right, but I did upload the helper file adding @NApiVersion 2.0 with no issue
actually, I just edited it in place, not upload
s
OK, that suggests that helper file passes the validation police check!
Also, I do think this error was only for SS2.1 - so backing off to SS2.0 for NApiVersion may have also circumvented the issue. However, that also means your script is running on older technology.
w
Both are 2.0
k
your account isnt set to run 2.x scripts in 2.1 is it? did they actually change this in 2021.1?
they mentioned this was going to happen
w
They are explicitly 2.0, so they should run as 2.0, correct?
s
yes