In a map/reduce script is there any way to pass a ...
# suitescript
m
In a map/reduce script is there any way to pass a small amount of data (like a single array) directly from the getinputdata function to the summarize function?
e
Do the
map
and/or
reduce
stages need this Array as well? If not, and it's not too expensive, you could just move the retrieval of the Array to the
summarize
stage directly.
m
Nope just summarize. I'm doing a suiteql query in the getinputdata method to pull vendors i need to make active, but want to pass this array of vendor ids to the summarize method to then make them inactive again
(in the reduce i'm looping through a few dozen journal entries passed along by the getinputdata function and updating the vendors on lines on the journal entries, so I need those vendors marked as active for the entirety of the reduce stage. Not using a map stage for this one)
a
You can send those IDs as keys to your summary stage from reduce, then build your array there and do what you need to do.
Copy code
const myVendors = [];
summaryContext.output.iterator().each(function (key, value){
    const sVendorId = key;
    myVendors.push(sVendorId);
    return true;
});
Your reduce could look like this:
Copy code
reduceContext.write({key: sVendorId, value: ''});
This does not look like a good design, as soon as you have many Vendors in your summary you could run out of governance in your summary stage.
m
It's about 400 ids in a single array, I was looking into building out a file but this seems a bit better scoped to me? Thank you for the suggestion alien
In order to do this would I have to pass the context into my getInputData function and call context.summaryContext you think?
a
No, pass your data down to reduce, there you pass your data to summary.
m
oh, unfortunately I don't think that would work. The idea is to pass from getInputData directly to Summary, there's no use for this data in the reduce function. Thanks though!
a
As far as I know there is no way to pass data from getInput to Summary, is not the way it works, by design it does not work like that.
e
Ha I'm currently (inheriting) writing some logic that needs to activate then inactivate records. I have one M/R containing the activation logic, which triggers another M/R containing the actual processing, which subsequently triggers a M/R containing the inactivation step. I use the
reduce
stage instead of
summarize
to do the active toggling because
summarize
is not parallelized
And I concur, there's no clean way to just pass-through data. You could write the IDs to a file during
getInputData
and read the file in
summarize
m
That's the way I'm leaning/working on eric (writing to a file), yeah the 3 m/r would be a lot... this is only one of 4 m/rs i'm writing for my accounting team even
e
FWIW I'm passing the record IDs between my two M/Rs using files.
👍 1
n
If the id's are unique, couldn't you just call a SuiteLet that does the logic you're talking about, passing it the id of the record you need processing, less jobs using processors, closer to real-time updates. Just a thought, a thought without the full picture of course 😉
m
Thanks for the sugestion NElliott, the problem is that I need to make the vendors active in the getinputdata stage and then active again in the summary stage, so it's two steps and I need the vendor ids to be available at both steps
👍🏻 1
567 Views