logo

NJP

Is it possible to become faster with no quality loss?

Import · Jul 19, 2018 · article

Have you ever wanted to save time on auxiliary actions while doing something more important?

Every time you need to draw a dialog window or make and ajax call - it requires writing several strings. Not a big deal, but due to human nature - you may omit a symbol or forget to pass correct parameter and spend time on fixing it.

Here at ScienceSoft we value our time and development effort and therefore we constantly improve our development process. Because we believe - if we improve our internal processes and mechanisms - we are eligible to offer improvements to other.

ServiceNow offers unique opportunity for every development team to speedup development by using shortcuts! Did you try to type "vargr" in the Script Editor of Client Script form and click Tab? If you try - you will see how it coverts into:

var gr = new GlideRecord("");
gr.addQuery("name", "value");
gr.query();
if (gr.next()) {

}

this became possible due to Editor Macros available OOTB

https://pdi_name.service-now.com/syntax_editor_macro_list.do?sysparm_query=

it would be mistake not to use this mechanisms so we decided to create shortcuts for cases of drawing dialogwindow and making ajax call:

  • Ajax call (could be used in Client Scripts) - just type "varga" and click Tab

image

var ga = new GlideAjax(''); // add ajax name
ga.addParam('sysparm_name',''); // modify ajax function name
ga.getXML(parseResponse);

function parseResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
}

Example: Ajax call shortcut

STEP 1: type "varga"

image

STEP #2 - click Tab

image

Example: GlideDialogWindow

image

var gdw = new GlideDialogWindow("ui_page_name"); 
gdw.setTitle("SCI Dialog Window"); 
// gdw.setPreference("text", text); //Pass parameters into the dialog if needed   
gdw.render(); 
View original source

https://www.servicenow.com/community/developer-articles/is-it-possible-to-become-faster-with-no-quality-loss/ta-p/2330358