How can I optimize my Script Include for better performance in large-scale ServiceNow instances?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2025 05:12 AM
I’ve written a Script Include that works well in dev environments, but it starts slowing down noticeably in our large-scale production instance. Are there best practices for optimizing performance in Script Includes, especially when dealing with GlideRecord queries and loops? Any profiling tools or logs you recommend checking?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2025 07:45 AM - edited 07-23-2025 07:47 AM
It depends completely on the Script you are running. Things that can cause performance issues can vary, like querying a a massive sys table, such as sys_audit, or doing multiple nested loops of GlideRecord queries, especially when creating records as a bunch of supporting back end records get created/business rules/other system activities run. Without seeing your script, I can't give exact suggestions, but looking to optimize things where you can, here are some examples. Instead of doing a multiple nested GlideRecord query, if you had simple information that you needed, it may be better to build a dynamic object of the information and do your next query with that info. ServiceNow also has some APIs that allow for update of multiple records, if they share the same value, such as updateMultiple() and deleteMultiple(). There are other things as well, such as using getRowCount(), which SN does not recommend using, and use GlideAggregate instead as it offers much improved performance. Also in terms of checking slow scripts, SN offers this OOTB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2025 08:51 AM
Just some general tips:
- Optimize your queries (Best practices)
- Use .setLimit() where it makes senses
- Use GlideAggregate, when only require a count of records.
- Check if GlideQuery gives you any performance improvement over GlideRecord.