Mark C
02/04/2025, 8:23 PMfunction map(mapContext) {
log.audit('map', mapContext);
var queryValues = JSON.parse(mapContext.value);
log.debug('queryValues', queryValues); //works
mapContext.write({
key: queryValues.values[0],
value: {
lineId: queryValues.values[1],
lineItems: queryValues.values[2],
unitCost: queryValues.values[3]
//these all show up in logs in their proper array locations
}
});
}
⢠In Reduce, I'll run the logic, but for reasons I can't find, the array isn't able to separate into each key:value pair. I get key and then the first value is holding all the others, leaving the last 2 as null.
//issue: Need to pass key and the other 3 values to call them in transactionline.field logic in reduce
function reduce(reduceContext) {
var tranId = reduceContext.key;
var lineId = reduceContext.values[0];
var lineItems = reduceContext.values[1];
var unitCost = reduceContext.values[2];
log.debug({title: 'Tran ID: ', details: tranId}); //works, so I know that 'Key' is successful
log.debug({title: 'Line ID: ', details: lineId}); //brings array - need to parse/split {"lineId": 1, "lineItems": 299, "unitCost": 24.88}
log.debug({title: 'Line Items: ', details: lineItems}); //no value
log.debug({title: 'Unit Cost: ', details: unitCost}); // no value
//other stuff happens here once I have those values available as objects.
}
When I look for sample codes, they're all either a. only 1 key and 1 value, or b. they use saved search instead of query. That's problematic for me since it's several jumps/JOINs to get the values I need.
I'm sure there's an easy answer, but I'm stumped. Thanks!!Anthony OConnor
02/04/2025, 8:54 PMvar reduceValue = JSON.parse(reduceContext.values);
I think if you just add that line at the start of your reduce... and then update all your references to change reduceContext.values
to reduceValue
you should be good.Mark C
02/04/2025, 10:17 PM