1

How can I upload a file to Netsuite File Cabinet automatically?

would nLapiRequestURL("Server1/database1/NDT/ftp.csv work?

File is to be fetched from a server within company.

I need to import CSV file to the cabinet automatically once a day.

  • It looks like you might want to use nlapiCreateFile(). https://netsuite.custhelp.com/app/answers/detail/a_id/10255/ – tatorface Oct 10 '14 at 14:07

1 Answers1

2

I think that the simplest way to go about this is:

  1. Place your CSV file into a location that is publicly visible(obviously, this only works if it's not sensitive information! PLEASE PLEASE PLEASE don't do this if you don't want the whole world to see it!)
  2. Create a scheduled script in NetSuite. Set the deployment to run daily, at whatever time you deem best
  3. In your scheduled script, use nlapiRequestUrl (NS help doc) to get the file from wherever you placed it (Note that there is a 5mb size limitation!)
  4. Use nlapiCreateFile (NS help doc) to create a file
  5. Use nlapiSubmitFile (NS help doc) to submit it to the file cabinet

Sample code:

var response = nlapiRequestURL('http://yourserver.yourcompany.com/somecsvfile.csv');
var csvDataInBase64 = response.getBody();
var file = nlapiCreateFile('mycsv.csv', 'CSV', csvDataInBase64);
nlapiSubmitFile(file);

There is no error checking or anything in that sample, but it should get you started.

If security matters(see point 1 above!), you are likely best off sending the file via web services. See https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/SuiteTalkWebServices.html for more information.

starholme
  • 121
  • 1
  • 3
  • Thank you for your reply. Your code helped to get started. I have written a script which downloads the file from FTP servers in the file cabinet and then performs Variable mapping. However, I was hoping if I could Improve it a bit. instead of pointing to one single file at time. Is it possible to download a batch of file to file cabinet by performing a comparison between ftp server and file cabinet. For example, if there is a new file available on ftp it downloads it to file cabinet w/o me pointing to it specifically?? Thanks – James guilford Nov 20 '14 at 19:42
  • That's really hard to say. I guess it depends on what operations you can do to the FTP server using url parameters. I suppose there might exist some sort of search or directory listing. Probably best to talk to the FTP server administrator for assistance there. Good Luck! – starholme Nov 24 '14 at 02:19