irurzo
07/15/2021, 5:18 PMI have a MR that reads a CSV file and creates a json object, Im using eric, solution
csvFile.lines.iterator().each((line) => {
const w = line.value.split(',');
const obj = {};
log.audit({ title: 'line', details: line });
log.audit({ title: 'line.value', details: line.value });
log.audit({ title: 'w', details: w });
if (headerCounter === 0) {
w.forEach((header) => headers.push(header));
headerCounter += 1;
} else {
w.forEach((el) => {
const headerName = headers[dataCounter];
if (!obj[headerName]) {
obj[headerName] = el;
}
dataCounter += 1;
});
fileData.push(obj);
}
return true;
});
The problem is that the object is being created like this
{
"'import_profile'": "'BBL_TT'",
" 'itemid'": " '24152'",
" 'upccode'": " '840154708304'",
}
With double quotes, the csv has data like this
'itemid', 'upccode'
'123', '456'
Should I be creating the csv without quotes? How do I handle a multiple select option for a field, I was doing something like this
'[1,2,3]'
But this separates the three values as Im separating by comma on the function.battk
07/15/2021, 5:21 PMbattk
07/15/2021, 5:21 PMbattk
07/15/2021, 5:22 PMbattk
07/15/2021, 5:23 PMbattk
07/15/2021, 5:23 PMirurzo
07/15/2021, 5:34 PM