In a Map/Reduce script I need to return a searchOb...
# suitescript
e
In a Map/Reduce script I need to return a searchObject. If there are 30K results, are all of them passed to the next stage? Or do I need to do some pagination?
e
If you're just returning the
Search
Object, then you don't need to page; the next stage will be called on each of the results.
1
e
Awesome, thanks Eric!
I guess there is no equivalent when using N/query 👀
m
This SA article implies that you can return an object using suiteQL, but the one time I tried, my getInputData function just hung until it timed out.
Copy code
return {
            type: 'suiteql',
            query: suiteQL,
            params: [271]
        };
e
Thanks for the reference Mike
I stumbled upon an article from Tim Dietrich, and he uses pagination manually to get all the rows
e
^^ This actually worked for me; I wasn't aware of it so thought I'd test it out.
Copy code
define([], () => {
  function getInputData() {
    return {
      type: 'suiteql',
      query: 'SELECT * FROM customrecord_sma_config'
    }
  }

  function reduce(context) {
    log.debug({ title: 'result=', details: context.values.map(JSON.parse) })
  }

  return { getInputData, reduce }
});
🙌 1
Logs results for each record with field values as expected
1
It's undocumented, so I probably wouldn't rely on this heavily, but it's interesting to know it's possible/in development?
👀 1
e
Very interesting!
For my use case it is crucial that all the rows are returned, because each line is an item for an invoice. Some invoices have 2 or 3 items, so I group them in the map stage, and create the invoice in the reduce stage. Missing results in the query would result in inaccurate invoices.
w
Been using suiteql-query as getinput pretty often. Have not had any issues with it. The SA article is part of the documentation, so I'm considering it documented. https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_158039627694.html
e
Oh interesting. Seems like a gap in the docs for
getInputData
then
w
Definitely! Everyone should comment that help section. 😀
2
s
Yes, all the rows will get sent to
map
- indeed in my experience
map
will not even be called until the search in
getInputData()
has completed entirely.
For this reason, MR scripts are no better than Scheduled Scripts if you have a search that times out; the search timeout error will happen prior to any
map
invocations 🙂
w
What kind of timeouts have you encountered in getInputData? I think I've seen getInputData's that have been running for almost an hour using a search.
s
I don't remember the exact time limit - it's whatever amount of time it takes for NS to throw the timeout error 🙂
I did just find a note I had that says getInputData has a 60 minute time limit.
👍 2
That's perhaps separate from the search timeout error that can be thrown in various script types, but perhaps the limits happen to be 60?