sure, basically you get all of your data (IDs if p...
# suitescript
c
sure, basically you get all of your data (IDs if possible) in your "getInput" phase. For EACH result that you return from getInput, the map phase function will execute to allow you to group your results by some category (if needed). Then the reduce function will run on each map phase result and then you get the summary phase which you can spit out some data if you want
👍 1
s
My scenario is that I need to update fields on the JE lines with data from a saved search. Get Input Data: Run search for line data - which will provide list of all JEs and their lines that meet criteria. Map: Group the input data by JE Internal Id. Reduce: Load a single JE, and process the lines/save JE. Summary: would provide information about what was processed and what errored out. Sound about right?
c
Are you getting JE lines or JE parent record IDs
you don't have to have the map AND the reduce phase as well.
you need 1 or the other.. like in this case if you go ahead and get all JE IDs (if thats what you are getting) and group by ID in your search, then in your map phase for each JE ID, you can do your thing
s
I see. I’m trying to get JE lines where a field value is missing.
c
ok so then yeah, you can get all of those, group by their parent ID and then in the reduce, load each JE and process the lines that you got
off the top of my head your process seems good
s
Where I get confused is the ‘group’. If I have multiple lines/rows of data, how is it going to group by internal id
c
the map phase would run on each line that you get in get input phase
so you'd group them by doing a context.write() where the key is the JE parent ID and the data is the actual line you got back from the search
it'll keep appending them by that key so at the end you'll have a list of like {JE_ID : JE_LINES}
it makes a key:values pair
s
would it load and save JE for each line that meets search criteria?
I just gotta try it.
but thanks a ton for helping.
c
so each line you get in getinput phase would be grouped w/ the parent JE... so in the reduce phase, you'd load the JE which is your key and all of your values are the JE Lines that you grouped in the map phase.
so 1 load for the JE and 1 save
s
But I got to convert multiple lines of the JE into a single value/object so you have 1 unique JE with 1 Value that has an object structure with all the data in it, correct?
c
you do that conversion in the map phase.. so lets say your get input phase returns 10 JE Lines.
Your map phase will run 10 times. Once per JE line.
s
Okay.
c
each time it runs, you write the JE lines to its parent ID so by the end when you get to reduce, you have JE_PARENT_ID_KEY : LIST_OF_JE_LINES
s
okay.
c
the reduce phase will run 1 time per grouping.. so JE_123: JE_123_LINES .. you'll load the key and then look at the lines
s
so you said I wouldn’t need both map and reduce, but this sounds like I would need it.
c
cool
yeah you will in this case it seems
s
Okay! This super helpful. I really appreciate it.
c
if you don't ever need to group things, then you don't need both but in this case you need to group so it is valid
np