0
votes

I'm trying to import CSV files automatically into Netsuite . ( For example, I'd like netsuite to check a specific root folder once a night and pull in or import those CSV files in to Netsuite. For example, I'd like some BOM information to be imported and mapped to Netsuite variables?

Is this possible? if not, would I at least be able to notify the user that there is a new file in a specific folder waiting to be imported?

p.s can i import regular xls files instead of csv?

Thanks for all your help.

Cheers,

James

Update this is what I have so far, not sure if It would work as one is SuiteScript one Portlet

function scheduledimporting(type){

var csvMap = '15'; //saved CSV import id
//var csvFile = nlapiLoadFile("5828"); //csv file id from filecabinet                
var urlrequest=nLapiRequestURL('https://...........',null,a);
var body=response.getBody(); //get the body of the message 
var csvImport = nlapiCreateCSVImport();//creating a new csv import

/***
If the file that I'm pulling in is a CSV, would i get the body as CSV?
DO I still need to go through Prsing the body and transform it to JSON Object
If I do, how would I transfer it back to CSV ? 
***/
csvImport.setMapping(csvMap);//setting import map
csvImport.setPrimaryFile(body.getValue());//file to be imported
csvImport.setOption("jobName", "Test1111");//setting job status' job name       
var csvSubmitId = nlapiSubmitCSVImport(csvImport);//submitting the CSV

}

2

2 Answers

1
votes

There are a couple of steps to do this.

  1. First create the CSV Import Mapping that you want the script to use. When saving the mapping, there should a field named 'Script Id'. The value in this field will be used by your script.

  2. Create a scheduled script that will check the folder location for new files and trigger the import automatically. In this scheduled script, you will use the nlapiSubmitCSVImport() and use the 'Script Id' field above to trigger the CSV Import Wizard. Search nlapiSubmitCSVImport() in NS Help for more details.

  3. You can not import XLS files, only CSV files are supported in CSV Import.

0
votes

Unfortunately, I don't have enough reputation to add a comment to Rusty Shackles answer. You asked about automating this more, and while you can't do it directly in suitescript, you can definitely use the web service built into netsuite to push files into your account. This would require you to have a program on your local server that uses the web service to push a .csv into your NetSuite account at a set time each night. Then you can use the scheduled script to trigger the import sometime after.