I have a Suitelet script which has a button called "Download".
On click of that, it reloads the Suitelet page, gets desired data to create a CSV file and gets downloaded on local machine.
My problem is, when I open the CSV file, it shows some HTML code.
But if same content I am trying created file and save it in File Cabinet, it shows CSV file content as expected.
Please help me how to fix the issue.
Here I am adding the code for reference:
//Headers of CSV File separated by commas and ends with a new line (\r\n)
var csvFile = 'Item,Std Cost(Tonal),Std Cost(Custom),Include Item For Stc Sync,Include Location For Stc Sync(From Location),Location(From Location Configuartion)\r\n';
for(var c in allItemWithStcVariance){
//Add each result as a new line on CSV
csvFile += allItemWithStcVariance[c].item_name+','+allItemWithStcVariance[c].item_std_cost+','+allItemWithStcVariance[c].item_std_cost_custom+','+allItemWithStcVariance[c].item_include_for_stc+','+allItemWithStcVariance[c].item_include_loc_from_loc+','+allItemWithStcVariance[c].item_location_name+'\r\n';
}
for(var x in notAvilableIcrForLoc){
//Add each result as a new line on CSV
csvFile += notAvilableIcrForLoc[x].item_name+','+notAvilableIcrForLoc[x].item_std_cost+','+notAvilableIcrForLoc[x].item_std_cost_custom+','+notAvilableIcrForLoc[x].item_include_for_stc+','+notAvilableIcrForLoc[x].item_include_loc_from_loc+','+notAvilableIcrForLoc[x].item_location_name+'\r\n';
}
log.debug("csvFile", csvFile)
//Creation of file
try {
var fileObj = file.create({
name: 'STC Variance Details.csv',
//name: 'STC Variance Details- ' + date.split("(")[0] +'.csv',
fileType: file.Type.CSV,
contents: csvFile, // contains comma separated string
encoding: file.Encoding.UTF8,
//folder: 2680
});
context.response.writeFile(fileObj, true);
}catch(ex){
log.error("Error Downloading file", ex.message);
}
Thank you
Ashabari Jena