Hi Guys, Can any one help me? I am trying to prepa...
# suitescript
p
Hi Guys, Can any one help me? I am trying to prepare a CSV data in the script and creating a file to it. But i am getting "UNEXPECTED_ERROR", but if i do it after some time i'm able to create a CSV file.
b
What does the code look like
p
Hi battk, here is the custom function function prepare_csvfile(csvData){ var result, ctr, keys, columnDelimiter, lineDelimiter, data; data = csvData || null; if (data == null || !data.length) { return null; } columnDelimiter = csvData.columnDelimiter || ','; lineDelimiter = csvData.lineDelimiter || '\n'; keys = Object.keys(csvData[0]); result = ''; result += keys .map(x =>
"${x}"
) .join(columnDelimiter); result += lineDelimiter; csvData.forEach(function(item) { ctr = 0; keys.forEach(function(key) { if (ctr > 0) result += columnDelimiter; result += '"' + item[key] + '"'; ctr++; }); result += lineDelimiter; }); return result; }
I am calling this custom function from Map/Reduce script summary stage
csvfileinfo = prepare_csvfile(failed_Array); var fileObj_1 = file.create({name:'test.csv',fileTypefile.Type.CSV,contentscsvfileinfo}); fileObj_1.encoding = file.Encoding.UTF_8; fileObj_1.folder = 1381273; var file_Id = fileObj_1.save();
b
unless you plan on working closer with support, stop using suitescript 2.1 and use suitescript 2.0
p
I also tried with doing in 2.0 but still i am facing the issue
and this is not happening all the time
b
if its the same data, that weird
p
if it is failed to create CSV file first time & if i try it doing again surprisingly it will work.
b
if its different data, then you probably need to share what your inputs are
p
It is same data
b
my advice here would be to hardcode your inputs
and if it still is inconsistent, share it with support
p
Ok
But can you tell me that how should be the final CSV string
I am trying to prepare like this
"externalid","entity","memo","class","custbody_del_psp","department","location","custbody_coi_tv_auto_assgin_gui","trandate","sublist_item_item","sublist_item_amount","sublist_item_tax1amt","Error" "consumer_adm_254706117","consumer_adm_13233001","254706117","4","cashier","1296","385","True","07/10/2019","3128","9.00","1","Invalid entity reference key consumer_adm_13233001." "consumer_adm_254706117","consumer_adm_13233001","254706117","4","cashier","1296","385","True","07/10/2019","3129","100.00","5","Invalid entity reference key consumer_adm_13233001."
every thing in double quotes
b
i think thats your output
its the inputs you want to hardcode
p
Yes, i am trying this now by hardcode.
let me check if any issue in file preparing.