Running a saved search that takes, from the ui, li...
# suitescript
s
Running a saved search that takes, from the ui, like 30-60 seconds to load. However, in my map/reduce where I am doing search.load(""), it has been stuck in getting input data for 4 hours. Any idea of how this could be sped up, or if it's just a glitch?
c
Sounds like you got yourself into an infinite loop. 4 hours though it should've tanked itself by now.
If you have a runaway script, you may have to contact support
s
man! the only thing in the getInputData is return search.load("mysearch"). So I don't think it could be an infinite loop on my side at least
s
This happens quite frequently in a particular client account of ours... They pay for Netsuite advanced support, and have yet to get a resolution on it. I will let you know if they ever give us any information.
Sometimes it just "fails" with no warning/error and decides it will not run the search, about once or twice a month
s
Why is netsuite sooooo slow. 300k records shouldn't be that hard to pull data back on lol
s
Well it's more peculiar that you can run the search in the UI in relatively short order, but the script just takes hours and hours
c
Can you run the search in the console successfully by chance?
s
how would you run it in the console? Meaning like a client script and debugging into it?
s
Copy code
require([
    'N/search'
], function (
    search
) {
    window['search'] = search;
})

// run the search manually
c
Yeah in the console load the search and see if it runs. Kind of like what Sandii posted above but you actually do the search logic and run it
s
Seems like it did. I only returned 50 though
There are 300,200 results
c
I'd run it a little more wide open. It sounds like its just a netsuite goof but if you can get the code to run in the console for all of it, it can pretty much confirm it
s
Is there a single line easy way to run it for all 300,000 in the console?
s
I’ve experienced this exact situation in several scripts with different saved searches. Netsuite hasn’t been much helping in figuring out the cause, but when I have more than about about 30-45 thousand results in a saved search, the time it takes for getInputData to complete starts to increase very badly. It doesn’t scale in a linear fashion above that. 90,000 results could take 4 times longer than 45,000. 180,000 results make take 6 times longer than 90,000, and so on. I have seen instances where gID ran for many hours when I had hundred of thousands of results, then finally the map phase started. There were no errors. My only solution so far is to limit GID to returning only the first 30 thousand results, then keep re-submitting the same M/R script task until there are no search results left.
netsuite 1
Doing it in smaller batches of 30 thousand or less it will actually complete faster, because of this strange issue
netsuite 1
s
that's ridiculous
s
yes it is
however, it’s worth a try. The exact cutoff could vary from account to account based on any number of factors invisible to me.
One way to experimentally find the sweet spot is to strip your M/R script down to just the getInputData stage returning the search.load, and having no code in the map or reduce phase functions. However, DO include a summarize functions, even if blank, because if you don’t, you can’t get the end time of the script for some reason.
Then, start with 5000 results, and run it, noting the start and end times. Then try with 10 thousand, and so on. Keep increasing until you see the time per result start to actually decrease.
You could maybe try to see if SS 2.0 vs. 2.1 makes a difference. In SuiteScript 1.0 and 2.0, creating and re-sizing large arrays is very inefficient and takes a ridiculous amount of time. I think that is due to a performance bug in the older JS engine. SS 2.1 does not have the same issue. Though, it could be something with NetSuite’s infrastructure itself, in which case the SuiteScript version won’t matter.
c
Also how many columns are you returning? a shitload of columns will slow it WAY down
✔️ 1
s
yeah, try to reduce columns to a minimum, and avoid large text columns whenever possible.
s
My scenario of the search taking 12+ hours sometimes is only 3 columns, but they are Grouping/Summing by date so it's possibly related to that
s
We have seen this happen with searches only returning one or two columns, even just the internal id column. It definitely has something to do with the # of results.
s
@creece 2 columns
s
Sometimes, talking about my workarounds to Netsuite' out loud makes me feel like i’m describing an abusive relationship, and people hearing me are thinking/saying “that’s not normal” or “no one should have to put up with that”
😍 1
c
Copy code
require(['N/record', 'N/search', 'N/format'],
function(record, search, format) {

    const MY_SEARCH = search.load({
        type: search.Type.ENTITY_GROUP,
        id: 'customsearch789'
    });

    console.log(MY_SEARCH);

    const MY_SEARCH_RESULTS = MY_SEARCH.runPaged({
        pageSize: 1000
    });

    console.log(MY_SEARCH_RESULTS);

    var results = [];

    MY_SEARCH_RESULTS.pageRanges.forEach(function(pageRange) {
        MY_SEARCH_RESULTS.fetch({index: pageRange.index}).data.forEach(function(searchResult) {
            results.push(searchResult);
        });
    });

    console.log('# Search Results: ' + results.length);
});
Run this in the console and replace the searchId and type with yours. See if it'll give you the results
s
@creece it errored with this. grrrr { "error": { "code": "", "message": "null" } }
Man, it's ridiculous. it took almost 3 minutes to return 2000 results
s
this might be a good time to try SuiteQL. I have heard it performs better, but haven’t had a good test case to prove it.
s
ohhhh, yeah I need to learn it
however, idea. download the results to a csv file, then load that csv file in the getInputData and convert it to csv
s
for a two column saved search, provided you don’t have a ton of filters, it should be an easy conversion
s
there are like 10 filters
s
yeah, that could be time-consuming. it depends on the filters
s
Think I may just convert it to a csv since it's 5mb (under the 10)
👍 1
I need to learn the sql piece though!
just to make sure, that is the same as using n/query right?
✔️ 1
s
Here’s a basic M/R template for running SuiteQL. won’t help with converting a saved search to SuiteQL, but still handy. Interestingly, if just returning the query itself form getInputData, you don’t even need the N/query module. Otherwise, yes, the N/query module is needed to run SuiteQL ad-hoc throughout a script.
the
.asMappedResults()
function on SuiteQL results is also really convenient
s
That's awesome @scottvonduhn! Is there a way to build or try the sql in netsuite?
e
s
Is there a helper for these queries? For instance, I want to get line level data on a sales order, which appears to not be in the transaction table without a join
s
transaction lines are indeed a join in suiteQL