I'm using a Map/Reduce script that gets a list of ...
# suitescript
e
I'm using a Map/Reduce script that gets a list of SKUs in getInput then makes an API for each SKU in the map stage. I'm looking to send a CSV file via email at the end of all of it but can't figure out how to persist an Object? I have a global variable of "itemArray" and am using itemArray.push() in my map stage, but when I log out the "itemArray" variable, it's an empty array. Could someone point me in the direction of passing all the combined data returned from the API calls into the Summary stage (or a way to call a function once, after all the map stages are completed)?
s
You cannot use global variables in an MR. You can write down to reduce and process in there (just use a same dummy key for every stage of the map). Or you could use
summarize
(if you are already using reduce) at the end to combine all the data into a single csv.
Summarize only gets called after map/reduce are finished
e
Thank you - this gets me moving in the right direction
c
reading stored data from the context in the summarize phase is def what you want
e
Correct, if you do not need to group data, just use the same key to send the data from map-to-reduce and you will get all your data in a single group in the reduce stage
e
Thank you all. I figured it out eventually. I assumed that if I used the same* key in context.write, that the value would get overwritten each time as apposed to appended. Ended up sending the email in the reduce stage (as I wasn't using that)