how to create empty csv file with a name generated...
# suitescript
v
how to create empty csv file with a name generated including timestamp? could anyone please help me in suitescript?
k
define(['N/file'], function(file) {
function createCSV() {
// Get the current timestamp
var timestamp = new Date().getTime();
// Create the filename with the timestamp
var filename = 'MyFile_' + timestamp + '.csv';
// Create a new file
var csvFile = file.create({
name: filename,
fileType: file.Type.CSV,
contents: '',
folder: -15 // This is the internal ID of the folder where the file will be saved
});
// Save the file
var fileId = csvFile.save();
return fileId;
}
return {
createCSV: createCSV
};
});
Please note that this script needs to be executed in a server-side script type (like a Suitelet, Scheduled Script, etc.) because client scripts do not have access to the
N/file
module due to security reasons.
d
☝️ Looks the the ChatGPT answer might actually work for once 😆