What's the best way to pass a record in the mapCon...
# suitescript
c
What's the best way to pass a record in the mapContext to a map() function? When I pass a custom record, getValue() no longer works: TypeError: configRecord.getValue is not a function
b
its no longer a record, its a string
true news 1
c
Yeah I guessed as much - bit of a pain
lots of downstream code assumes it's a record.
s
so, you can’t really pass a record, anything you pass from map to reduce has to be serialized as a JSON string, with a key. Any values with the same key will be combined together in the reduce phase. You can either just pass the record internal id, and reload it again in the reduce phase, or pull out the specific field values you know you will keep, put them into an object, and pass that object to reduce as the value. Alternatively, shift all of the record processing to just the map or reduce phase if you can, so that you only need to load the record once.
c
I'll just reload the record. Doesn't feel the best doing that but many subsequent bits of code use that record and I don't want to make massive changes.
Thanks!
s
this is one reason I don't automatically choose MR script type just because it's newer than Scheduled.
s
If you plan and build for a M/R script up front, it’s fine. If you are trying to break apart a Map phase or adapt a different script type to M/R, it can be a pain, though.
c
Yeah, I'm retrofitting to this solution so it's providing inputs into an already existing library of functions
I've added an isolation layer which converts various things to JSON strings, objects, and records etc.
n
Pass the record id / type instead and load it in the map.