- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
As a follow up to my earlier blog, I was checking some of my old notes (can't find it now on community search) and stumbled upon a function that will let you check the SQL query and it's performance. gs.trace() appears to be yet another undocumented function in ServiceNow that will let you see the SQL query that the system generates whenever we issue a query() command. Along with the SQL query, it also let's you know how much time the system took to perform the query.
Where can I use this?
- During development on your development instance to fine tune your query for performance, evaluate which version of query/script works best, etc.
Sample:
var tableName = 'task';
var filterString = 'active=true';
var answer = false;
var getRecord = new GlideRecord(tableName);
getRecord.addEncodedQuery(filterString);
getRecord.setLimit(1);
gs.trace(true);
getRecord.query();
gs.trace(false); //set this to false to get only the current query
if (getRecord.hasNext()) {
answer = true;
}
gs.print('Record found:' + answer);
Note: trace() works only in global scope and seems to be working like session flag. So you have to reset it to false to stop seeing the SQL queries.
If you liked the content, please share, click helpful, bookmark or leave your valuable comments.
- 3,268 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
