How to upload a file to Netsuite File Cabinet Auto

2019-06-09 14:22发布

问题:

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.

回答1:

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.