Using if condition with setLimit enhance my code??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 10:56 AM
Hi Everyone,
Suppose, I am having a code:-
Here I am getting count as 1. {Because I am using if condition.}
------------Now Suppose I am enhancing my code as below-------------
---------------------------------
In this code I have added the set Limit , although my count is same i.e 1.
Now, I am having one query...does applying setLimit , it is enhancing my process time or both the code will take same time to process...??
And where we can calculate the process time..??
Thanks in Advance
Utsav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:05 AM
Hellow @Utsav JAISWAL
If you run these two in Background scripts, then the output shows you Script execution history and recovery available here (this will have hyperlink): Table: sys_script_execution_history
Without setLimit()
With setLimit()
you can clearly see the difference why setLimit(1) is always recommended as best practice where you want to work with only one record in the table.
Hope it helps!
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 11:21 AM
Hello @UTSAV JAISWAL
Without a doubt using setLimit enhances the performance. This is very evident because in servicenow it's recommended to process 1 million records in a batch of 10000 and is called very efficient. But running 1 million records is not. So, if you want to work on a limit of records, using setLimit is definitely recommended.
Also as @Vishal Jaswal already mentioned, you can run this in background script and check the response time system took. Also syslog_transaction table will store exact time.
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY