I was trying to change type of the file created during the process to csv format ,so that it can be opened in excel format.
Please find the screenshots in the attachments for reference.
In process, i created an output variable as below
${update_file(file_id,"whereusedlist.csv","application/csv")}
And the file is getting attached to the file upload widget but it is not displayed in csv readable format when we try to open in excel.
Please find the attachment for the format.
Could you please advise how to fix this issue?
function JSON2CSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
var line = '';
var head = array[0];
for (var index in array[0]) {
line += index + ',';
}
line = line.slice(0, -1);
str += line + '\r\n';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
line += array[i][index] + ',';
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
var array=[{"Id":1,"UserName":"Sam Smith"},
{"Id":2,"UserName":"Fred Frankly"},
{"Id":1,"UserName":"Zachary Zupers"}];
alert(JSON2CSV(array));
/*The output will look like
* Id, UserName
* 1,Sam Smith
* 2,Fred Frankly
* 1,Zachary Zupers
*/