Is it possible to use Map/Reduce to run a saved se...
# suitescript
j
Is it possible to use Map/Reduce to run a saved search and save the results as CSV file in the File Cabinet? I was able to write a scheduled script to run the search, and save it as csv in the File Cabinet, but the saved search is in the hundred thousand lines.
s
I don't see why not - you could use the N/file appendLine function to keep adding lines to an existing file. You would just need to make sure your MR script is using a single processor, and would definitely want to leverage the reduce function to avoid opening and then saving a file each time the map function is called (for each line), which could take forever.
Just be careful what you try running, as once a MR script starts, you can't stop it.
j
makes sense
somehow
thanks
s
Also, take a look at task.SuiteQLTask
it supports exporting a query to CSV, but not sure how large of a data set it supports
šŸ‘ 1
a
@JC You don't need a Map Reduce to do that, you can use the N/task module to do that and would be 100% native NetSuite background process without using processors as Map Reduces do...
šŸ‘ 2
j
I have used SuiteQL and it's awesome. Somehow accounting wants this to be exported to .csv and save to the cabinet.
@alien4u Will this allow me to run a very large search and save as a file in the file cabinet?
r
I recommend using N/task module as well as it will completely be done in the background. If you create a csv on your own, you will have to handle comma that may come in some columns, etc. And some other peskly little corner cases.
a
If you use
task.SearchTask
your script would be simple and asynchronous with few lines and native NetSuite functionality, meaning you don't need to worry about parsing lines or columns.
😲 1
ā˜ļø 1
s
I think the question is if there are limits on how much data it will export
j
right
a
If you can export it in the UI you can export it with N/task... is the same background process/functionality...
Break it in the UI to find your limit...
😁 1
The
task.SearchTask
is pretty much the same as exporting via clicking export to CSV in the UI...
s
When working with suiteql via the query module, there are 100k row limits, unless you have SuiteAnalytics Connect feature purchased.
j
so the limitation could come in the actual csv file
netsuite would handle the data well with N/task
s
Best to try exporting more than 100k rows via the UI and see if it works
j
true
trying that right now
so it did export 116,000+ lines
s
That's a good sign then
n
Does the system queue those SearchTasks if it's submitted more than once (already running) or too many are running at once?
ah implies it does in help: • Submit the search task to the NetSuite task queue using SearchTask.submit(). I'll take that as yes since it puts them on a queue.
šŸ‘ 1
r
I agree that the search task is the way to go. Writing to the file cabinet is is also possible (currently doing this with a massive n-ary tree json object file), but you have to keep in mind that map and reduce stages happen in parallel, so loading and saving the file will run into issues there. For my use case I build a bare bones tree in GID and save it, pass item IDs to map, gather related record data in reduce, and then load the file and insert my results into the tree in summary when execution is sequential again.
šŸ’Æ 1
In my experience, search tasks can actually run searches that would hang in the UI and hit limits via script, meaning search tasks are the ONLY way to run some searches which are sufficiently large. They seem to perform way better than alternatives as well.
šŸ’Æ 1
n
Presumably you could just write a simple scheduled script that just submits the search Task if you literally just need the output writing to a csv?
and it worked, the csv file was filled in with all 116,000 lines
it is scheduled, but it doesn't update the data every time it runs. Any ideas?
a
@JC There are some shenanigans/bugs with NetSuite FileCabinet files when you try to overwrite them, best bet, delete the file if already exist, create an empty one and make the searchTask do its thing.
j
That's what I thought
the person who requested this wanted the same internal ID for the file. I've already explained that is better to have the internal ID for the folder.
thanks!
a
If the name and folder where you save the file is consistent, they can use the folder Id to find the file or a combination of folder ID + fileName
šŸ‘ 1
j
@alien4u thanks for all the help!
šŸ‘ 1
n
Alternatively, load the file, set the content to empty and save it before you run the task.