Friday, May 24, 2019

How to create a script which parses CSV files

To create a script which can parse a CSV file using SuiteScript there are a few important steps that must be taken.

1. 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.
2. Upload the CSV file to 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.
3. Load the CSV file using nlapiLoadFile. Use the internal id from step 2 as fileID. Example Below:
4. Find a way to break up the file into parts. Below is an example which uses regular expressions:
5. 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. custom record or script parameters).
6. 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.
7. Optionally setup the script so it sends some kind of notification when complete (E.g. by sending an email).

No comments:

Post a Comment