Hi guys! I'm quite new with the Map/Reduce, so I w...
# suitescript
m
Hi guys! I'm quite new with the Map/Reduce, so I would like to ask help. I'm doing a script to import data to custom records from CSV. There is logic that normal import can't provide so hence the script. When I have new record to create, I first need to check if it already exists. Is it faster & more efficient to: 1. Do search with specific externalid every time in Map? 2. Do one big search and store details? a. If 2. is better: in which phase I should do the search and save details for later use?
e
In general, fewer touches of the NetSuite database will be better in terms of performance as those operations are expensive, thus my default answer would be #2. Without more context on the rest of the script, though, it's hard to say where that search belongs.
w
I'd say you test it. Just checking if an externalid exists is pretty quick.
b
id say do the search once for every external id, it makes it much harder to have data duplication issues
although you probably wont have any if you are actually setting the external id field
w
I'm guessing that he might want to update the records that already exist instead of creating new ones. Depending on how many records the table holds, it might be nice to pull out all
{ externalId, internalid }
and map it towards the data from the CSV-file before sending it through to map. Then in map, you already know if you need to update or create. Are there too many records in the table you might run into some governance and size-limitation. I would probably go for doing a search in each map. Simpler code to understand and maintain.
m
Thank you for your replies! At the moment the data file will be something like 500-1000 rows. But it is likely it will grow somewhere around 2000 rows in near future. But I'll continue with search inside map and let's see how big row amount that can handle 🙂 Thanks!