Hi, I have a question. I am trying to make minor e...
# suitescript
c
Hi, I have a question. I am trying to make minor edits to a script, but to do so I need to read in a test CSV. The current way a script works is to connect to a FTP and download and save the CSV.
Copy code
// download the file from FTP server
                var fileObj = objConnection.download({
                    filename: filename //"Name_######_csv" // filename
                });

                fileObj.folder = runtime.getCurrentScript().getParameter({name: 'XXXXXXX_files_directory'});
                fileObj.name = filename + '.csv';
                fileObj.save();

                var convertedData = Base64.decode(fileObj.getContents());
                log.debug("convertedData", JSON.stringify(convertedData));
Above is how the current script is written and works just fine. Below was my quick update for testing a file. When I check the debug logs convertedData and other objects are gibberish. (ex:M?Óü\u001eÊ&{õ\u000). Is File.load not the correct way to set the fileObj?
Copy code
var fileObj = file.load({
                     id: 12345
                 });

                var convertedData = Base64.decode(fileObj.getContents());
                log.debug("convertedData", JSON.stringify(convertedData));
b
be very careful about the naming of the files
im guessing that the original script did not add .csv to the filename, so netsuite assumed the file was binary
which was why it needed to be decoded
if your testing file has a name ending in csv, its probably not in base64 and does not need decoding
you can use File.isText if you want to be robust about if you need to decode from base64
c
ah ok I'll try that. I saw that they were setting appending the .csv so I thought it was a csv file, but I guess that is just being used for saving the copy.
Thanks
Thank you! That solved it. saving it as a .bin