You are currently viewing How To Get Query Execution Time in ServiceNow?

How To Get Query Execution Time in ServiceNow?

Hello Spectaculars,

Welcome to this new article of ServiceNow Spectacular.

In this article we discuss an amazing requirement where we find the time taken by system in execution of a query

Steps to complete the requirement :-

  • So, in requirement that we need to find the duration of creating a child incident.
  • For this we have created a UI Link called Create Child Incident
  • Placed the query in UI link
  • In query we have used StopWatch() class.

The code for UI action is as follows:-

function createChild() {
    var sw = new StopWatch();
// Fetch incident details
    var parentSysID = g_form.getUniqueValue();
    var caller = g_form.getValue('caller_id');
    var cat = g_form.getValue('category');
    var subCat = g_form.getValue('subcategory');
    var desc = g_form.getValue('description');
    var shortDesc = g_form.getValue('short_description');
    // GlideAjax Call
	var ga = new GlideAjax('CreateChildRecord');
    ga.addParam('sysparm_name', 'createRec');
    ga.addParam('sysparm_parentSysID', parentSysID);
    ga.addParam('sysparm_caller', caller);
    ga.addParam('sysparm_cat', cat);
    ga.addParam('sysparm_subCat', subCat);
    ga.addParam('sysparm_desc', desc);
    ga.addParam('sysparm_shortDesc', shortDesc);
	var answer = ga.getAnswer(); 
	var RUL = '' + answer;
	var link = '<a href=' + RUL + '>Link</a>';
    g_form.addInfoMessage("Time taken in creating child incident " + link +  "  is  " + sw.toString() + " ms  " );


Incident screenshots

  • How the UI action looks?
  • The message on click of UI action
  • The new child

Leave a Reply