I am trying to write the push below array as value...
# suitescript
d
I am trying to write the push below array as value for reduce stage i am not able the get values in reduce stage, when i retrieve context.values; i am facing an error unexpected u or unexpected L var x = [{"CUSID":"31","TN":"CUSTINVC204","AMT":"321.58","DD":"","TD":"1/14/2019","TT":"Invoice","DISC_AMT":"","ALT_NAME":null,"PAR_CUS":"000001 GOODYEAR EDI CUSTOMER ONLY"},{"CUSID":"31","TN":"CUSTINVC216","AMT":"233.68","DD":"","TD":"1/15/2019","TT":"Invoice","DISC_AMT":"","ALT_NAME":null,"PAR_CUS":"000001 GOODYEAR EDI CUSTOMER ONLY"},{"CUSID":"31","TN":"CUSTINVC222","AMT":"100.00","DD":"","TD":"1/15/2019","TT":"Invoice","DISC_AMT":"","ALT_NAME":null,"PAR_CUS":"000001 GOODYEAR EDI CUSTOMER ONLY"},{"CUSID":"31","TN":"CUSTINVC223","AMT":"100.00","DD":"","TD":"1/15/2019","TT":"Invoice","DISC_AMT":"","ALT_NAME":null,"PAR_CUS":"000001 GOODYEAR EDI CUSTOMER ONLY"}]
s
If you have this array in the map stage, I would recommend looping through the array and passing each value in it to the reduce individually.
Copy code
for (var index in x) {
    context.write({
        key: x[index].CUSID,
        value: x[index]
    });
}
that would be in your map phase, then in the reduce phase, read each value with
Copy code
var valueArr = context.values;
for (var index in valueArr){
    var tempValue = JSON.parse(valueArr[index]);
}
d
I am getting error unexpected u or unexpected L JSON.parse
n
presuming you've done as above it may be you need to stringify your value