this feels like a dumb question but if I run the f...
# suitescript
m
this feels like a dumb question but if I run the following:
Copy code
var someSearch = search.create({ [assume valid search here] });

var countOfResults = someSearch.runPaged().count;
if(countOfResults == 1){
     var one_result = someSearch.run().getRange(0,1);
}
Am I technically eating up more governance by running the search twice or does the runPaged meta data not incur governance?
s
runPaged()
is 5 governance units according to help. If you just need to get the first result I write it like this
Copy code
const firstResult = Seq(LazySearch(someSearch)).map(nsSearchResult2obj()).first()
you might try just your second line
someSearch.run().getRange(0,1)
and skip the first 'countOfResults'. If NS returns nothing from
getRange()
then you know there's no first result?
m
That would be a good approach for that scenario and I'll keep that in mind, but in this case I need to verify that I have only one matching result before using it or doing something else. Thanks for the input on runpaged using 5 pts I'll probably have to optimize this so that I'm not burning more pts than I need to
I'll probably just run getrange(0, 1000) and verify that the resultset isn't null and the length is 1
s
If you expect to have a small number of results just getrange() it so you have both the data and a count all in one
m
yeah it shouldn't be more than 1000 ever
hopefully only one as long as the filters are good
s
aye, so in that case just getting the results (if you need to get them anyway) once is an efficient scheme
m
cool thanks for the reply, it helps to talk stuff out while I'm still wrapping my brain around 2.0 lol
👍 1
b
in combaintion with PagedData.count
you will use 5 points for getting the PagedData if there isnt one result
and 10 if getting the PagedData and fetch if there is one result
m
hmm interesting
b
anything that tries to use the count in combination with getRange is lazy and wrong
m
lol
that's partly why I abandoned it
I noticed that it was built into the extension that I'm using to simplify the creation of my searches, so I wanted to know if I would be right to abandon the runPaged code for another solution
b
i no longer recommend that extension since im tired of seeing that code
m
I'm heavily modifying it at this point, but it did give me a good idea of how to start building the search calls that I needed
is search.createFilter preferred over the simple array that is used by the extension?
b
filters and filter expressions are different things
m
maybe the extension was written that way because it would be easier to handle all filters as filter expressions
b
filter expressions can represent more searches than filters