The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Kalaiarasan Pus
Giga Sage

We all have to implement a requirement commonly where atleast one record/result exists before we do some processing. Example, a emergency change has atleast one incident attached to it before we allow the user to submit it. We have atleast 6 different ways to do this query (probably more) and find if atleast one such record exists.

 

Some of the ways are include,

 

  • Using Gliderecord + getRowcount()
  • Using GlideAggregate + getAggregate(count).
  • Using a plain gliderecord + next().

 

There has been multiple discussion on the most optimal way to do this including the one here. But how do we know which is the best/fastest way to do this? Attached are different versions of the script, scanning the task table. The idea is to reproduce the results with the full table scan. 

 

The winner of the test was Gliderecord + setLimit() + hasNext() function. Using setLimit seems to be the trick for getting most optimal performance possible.

 

Note: ServiceNow seems to be caching the records after the initial query. So, do few runs to determine the average performance of different function calls.

 

If you liked the content, please share, like, bookmark or leave your valuable comments.

3 Comments