Scenario
Some records are not available for CSV import, but it might access through scripts. Therefore, a script might import records or use a CSV file to perform some other action.
Solution
To create a script that parses a CSV file using SuiteScript, some important steps are required.
-
If the goal is to add or modify records in NetSuite check the SuiteScript Records Browser and make sure the record type and fields to be modified are exposed to SuiteScript.
-
Upload the CSV file to the file cabinet. It should be renamed to have a txt extension so that SuiteScript can access the file contents. Then take note of the internal id of the file.
-
Load the CSV file using nlapiLoadFile. Use the internal id from step 2 as fileId, as following:
-
Find a way to break up the file into parts. Below is an example which uses regular expressions:
-
This should be a scheduled script (It is possible to save and execute from the UI so this script doesn't run on a schedule). Include code to prevent the script from timing out due to a high number of rows by having it reschedule itself. An example can be found in the article Scheduled Script Samples. Make sure the script takes note of where it left off (E.g., a custom record or script parameters).
-
If this script is adding or updating records in NetSuite, it should contain code which can check if the record already exists. This can be accomplished using Search APIs.
-
Optionally set up the script, so it sends some notification when complete (E.g., sending an email)