0

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 Answers2

1

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.

Rusty Shackles
  • 2,802
  • 10
  • 11
  • Thanks for your help Rusty,Would I be able to import the file from an external drive and not the File cabinet. ( Let's say a drive in a server, or local drive? ) . This would not require me to upload the file to file cabinet myself. Then the whole thing would be autmated? I haven't been able to find anything except nlapiLoadFile which uses the internal ID in the file cabinet right? – James guilford Sep 29 '14 at 23:28
  • NetSuite API does not have access to external drives. You will need to upload the file into your NetSuite file cabinet. – Rusty Shackles Sep 30 '14 at 23:27
  • Can I use nLapiRequestURL ? and access it through a link ? – James guilford Oct 03 '14 at 18:06
  • Not sure, I have not used nor encountered a script using that approach. – Rusty Shackles Oct 06 '14 at 22:00
0

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.

starholme
  • 121
  • 1
  • 3
  • Thanks for the info, Would you be able to elaborate more on this(how would I be bale to push the file to cabinet)? I just started working with Netsuite. and Should I use RESTlet or Suitelete? :) @starholme – James guilford Oct 09 '14 at 00:14