Is there faster solution than search.run.each() an...
# suitescript
m
Is there faster solution than search.run.each() and returning false to get the first result? I need the first element from a search, but we are needing a quick response time so I am trying reduce as much as possible.
s
Why do you only need the first result?
m
I need the very last transaction in a location. I'm trying to find the very last lot that was used in the specific location it's calling for by ID.
c
You can sort by transaction ID descending and use the getRange to get the 1st result.
s
search.run().getRange(0,1) will only give you only result. Idk if it would be any faster than run().each and return false on first result, though.
m
Yeah that's what I was trying (should've prefaced that) it looks similar response times
ablobsad
e
Add a formula numeric on your search and use
rownum = 1
👍 3
c
You can also cache the data depending on when you need it
m
@ehcanadian I'll give that a shot didn't realize that's possible
@creece It's for a rest endpoint for an outside program. I'm thinking about making a SQL / Redis local solution that just updates instead of waiting for NetSuite everytime
thanks all!
@ehcanadian that cut 200ms off the response, I owe you one!
👍 1
e
Glad it helped
r
Add a formula numeric on your search and use 
rownum = 1
<= how you retrieve the value using this approach?
e
Same as usual. The formula limits the result set to one row.
r
So this will be added as a search filter?
e
Yes