Search code examples
suitescript2.0

How to change delimiter/separator of CSV on file.create


I'm creating a CSV file using suitescript file.create method. Is there a way to change the delimiter/separator? I'm trying to use pipe(|) instead of comma(,).

I've already tried this

var csvFile = file.create({
         name : fileName + '.csv',
         contents: stringValue,
         folder: ****, 
         fileType: file.Type.CSV,
         isonline: true,
         separator: '|'
});

It does not work.

Thanks


Solution

  • If you are trying to handle the data with commas. You could try enclosing the values with double quotes "".

    var stringValue = '"A,B", B, C, D';
    
    var fileObj = file.create({
        name : testcsv.csv',
        contents: stringValue,
        folder: xxxx,
        fileType: file.Type.CSV,
        isonline: true
    });

    It should generate like this:

    enter image description here