Anybody experiencing Map/Reduce issues (specifical...
# suitescript
e
Anybody experiencing Map/Reduce issues (specifically with returned objects in the getInputData stage) with “Unexpected error” in version 2024.1.16.21644? We have a Sandbox experiencing issues on that version.
a
There is no easy way to resolve Unexpected Errors, for this case this is what I will do: • Create a copy of the search. • Start removing columns one by one and running the Map Reduce with a modification to immediately return on each other stage but the getInputData stage. • Once you identify the column that is making it fail, then you can think about how to deal with it. My unpopular recommendation: • Do not pass raw search results from getInputData to the next stage. • Use the native and proper N/search methods to get the search results in a meaningful structure and then pass that to the next stage.
e
Thanks. This is a M/R that has been working for years. In fact, works currently in production. however, it seems the sandbox was upgraded to this version and it has stopped working…
and true it is doing some work to build an object to pass to the next stage, not simply returning a search
t
@ec I have just hit this as well. it appears that is now any array of objects that is the issue. if you stringify your objects before you return them then it works.
Copy code
return results.map(JSON.stringify)
of course you need to JSON.parse at the start of the map stage. @alien4u we had to stop passing search results and query results, as we were hitting over the 4000 limit in search and 5000 limit in query. As well as seeing some corruption / weirdness when returning long text fields with over 100,000 characters in them
The test i set up and the results are
Copy code
return [1,2,3] //Works;

            return [{basic: 1}, {basic: 2},{basic: 3}]; //Fails {errors: ["{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":"An unexpected SuiteScript error has occurred"}"]}

            return [{basic: 1}, {basic: 2},{basic: 3}].map(JSON.stringify); //Works
e
!
Thanks, @Tim Pilgrim major annoyance (or even more than that, honestly) Just curious, is your environment on 2024.1.16.21644?
t
The only one of our customers that has reported this is on 2024.1.16.21644 yes
and so far only in their sandbox
e
How do we get NS to make sure this change does NOT get to Production sites ASAP???
t
raise a defect. we have just deployed a fix to our code across our customer base on the grounds that Netsuite will carry on and solve it after the fact.
a
Sorry to sound like a broken record, NetSuite support can easily and effortlessly come back with something like: • Since you are not using
N/search
native and documented methods we don’t know about that unexpected error and we don’t have a way or obligation to fix it, or prevent it to escalate to Production. That, again, is why I even when people don’t like it still insist in… properly gather your results in getInputData before passing them to any other stage.
t
@alien4u I get what you are saying but one of the value options is to pass an array in ...... at no point does it specify that the array must be in a string or must not be in an object. And the lack of documentation on this means that none of dev's have done anything incorrectly. by NetSuite documentation anything that is valid in an array should be passed correctly.
a
You are also right (100%) if the only thing that happens is passing that array of raw results and that = Unexpected Error… sure… still a NetSuite problem, but that is a lot harder to proof to them that using everything out of the book… when you deal with NetSuite support as much as I have done you know what I mean.
t
I know exactly what you mean about netsuite support hence writing a scratch mr script to prove what they have done.
a
Exactly, or avoid all together because 100% everything is using the native API, how much time did you save? ~40 hours of back and forth emails and calls at 3:00 AM from somebody at India that did not checked the time zone.
Long story short, use the native and documented API and be happier…
e
@alien4u not sure why you say this wouldn’t be supported? why is search the only supported means of using a M/R script?
from the “Terminology” help page getInputData The first stage in the processing of a map/reduce script. During this stage, your script must return an object that can be transformed into a list of key-value pairs. You use the getInputData entry point to identify the function that executes during this stage.
if anything, returning a search is a documented “hack” of sorts
another reference - though they specify “plain” Object, not sure if this is excluded
a
Because a Map Reduce is a type of script that is only possible to create using a language, called SuiteScript that has a documented API with possible functions and methods, and that anything outside what is documented even tho may be possible does not mean is official. Therefore, NetSuite Support (again) can easily and effortlessly reply: You are not using the system in the way it was designed and/or documented and therefore, we are not responsable. Figure it out.
e
Asking why this is outside of the scope of what M/R can handle? Acc to documentation I pasted, an object is indeed included. Is it not a “simple
" enough object?
a
Forget about my recommendations or advices… you are right… contact NetSuite support…
e
Haha I already did and have 0 conidence 😉 but i am truly asking about your use of M/R. I think the power of M/R is partially that you have control over each of the stages, including data
For example, you may query (or search) two different data sets and build a third from the results that yo couldn’t have gotten to without some parsing etc
a
You are still missing the point… Use the native methods, search.getValue, search.getWhatever, query.getWhatever… Then pass that to whatever stage you want in whatever script you want… when something fails it means NetSuite API failed… If you dont use the API then they can wash their hands…
e
Oh, what is failing here is the passing between stages, sorry I didn’t clarify. Nothing outside of the API. Nothing undocumented / unsupported
We’re just not returning a search object in the getInputData “return” clause
Well, look who came through in the clutch! all us non-believer (myself included) 😄
Copy code
To give an update regarding U2 Issue 782436 : SuiteScript > Map/Reduce > UNEXPECTED_ERROR, our QA was able to identify the possible root cause of the defect and has now assigned the issue to one of our Developers to find a fix.
A possible alternate solution is to use JSON.stringify on get_input stage.
We'll keep you posted for further updates on the issue.
They’re working fast, too
Copy code
This is an update regarding U2 Issue 782436 .


We would like to inform you that a potential fix has been identified and is now being verified by our QA engineers before releasing it to your account.


We will send another update once the fix is ready to be released.
Thank you for understanding.
150 Views