Thursday, February 14, 2019

CSV Import via SuiteScript

To automate the CSV imports whenever user uploads them or have a CSV import done on a schedule, follow the steps below:


1.       Create a Field Map for the CSV File.

Field Mapping offers a 1-to-1 relationship between the fields on the CSV File and NetSuite Fields.

a.       Navigate to Setup > Import/Export > Import CSV Record.

b.      Upload a CSV File and fill out the Import Assistant Form steps.

c.       Mapping Field Step: The fields the left of the screen are CSV fields and the fields on right are NetSuite Fields. Drag and Drop the CSV fields to center column, then match NetSuite Field with by also dragging that field to the center.


d.      Test the Field Map by saving and running the CSV import.

Click Save and Run


e.      Then check the CSV Import Status to see if it is successful. If not, make the necessary adjustment to their Field Map.


2.       SuiteScript Code

function csvImportFunc(){

var customerCSVImport = nlapiCreateCSVImport();


// setMapping(id) – id (parameter): Internal ID of the Field Map created Step 1.

// Navigate to: Setup > Import/Export > Saved CSV Imports.



setPrimaryFile(file) – file {string} (parameter):


The internal ID, as shown in the file cabinet, of the CSV file containing data to be imported, referenced by nlapiLoadFile. For example: setPrimaryFile(nlapiLoadFile(73)


Raw string of the data to be imported. For Example


fileString = "company name, isperson, subsidiary, externalid\ncompanytest001, FALSE, Parent Company, companytest001";




customerCSVImport.setOption("jobName", "job1Import");



3.       Upload Script

The Supported Script Type for SuiteScript CSV Import is Scheduled Script.

a.       Navigate to: Customization > Scripting > Scripts > Type: Scheduled Script

b.      Fill Out Form

c.       Script File: Find the Script or Upload Script.

d.      Function: Enter Script Function Name. e.g. csvImportFunc - For Script Example above.

e.      Save and Deploy: Click Button


4.       Deploy Script

a.       Select Schedule. Either single event or Schedule Repetitive Events.

5.       Check Status when script is being ran:

a.       Schedule Script Status – Navigate to: Customization > Scripting > Script Deployments > Status.

b.      Setup > Import/Export > View CSV Import Status.

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations. NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto. NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment