ScienceSoft
Tera Guru

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 

find_real_file.png

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"

find_real_file.png

STEP #2 - click Tab

find_real_file.png

 Example: GlideDialogWindow

find_real_file.png

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(); 

 

Comments
Fabian Kunzke
Mega Sage
Mega Sage

Hello,

I appretiate the tutorial, great work, really good exapmles. But: sadly i have seen too much code where it is just a long list of these macros with all the same undescriptive variablenames. This does make it not only hard to read the code, but with that hard to maintain and to expand. Honestly, the time saved by such basic code generation is often times lost when reworking the code.

Lastly: How much time really do you safe with those macros? I cannot think code with 80wpm, but i can type that fast. So instead of generating code, why not rather focus on minimizing it? From my expirience code macros like these do not minimize code, but rather coding time. Instead i think you should focus on writing code that is reusable and reuse that more and more. That will make you more efficient.

Anyways, just my opinion. In it self great article.


Greetings

Fabian

ScienceSoft
Tera Guru

Hi Fabian,

you are absolutely right - when it gets to the long list of macros - it is like learning new language that is very specific and only within your team. However that does not mean it is useless - there is always balance that needs to be targeted!

We do have more techniques and methods of developing faster and reducing human factor(we are going to share it later) - and this is only one way of achieving it. Hopefully it will help teams to realize what powerful instruments they have. And evey team may decide to use it or not 🙂

 

Thank you for your comments!

 

 

icerge
Giga Contributor

It's a nice tip! Thanks!

I personally prefer to use vscode for any script edits, especially, huge ones. There are many reasons for that, but that's not the point.

If I use SN script editor, I'd definitely write several snippets. I wish ServiceNow guys enable rich editor. Otherwise, it looks abandoned a bit.

In general, snippets keep save one's time from debugging of typos and API usage reference. It's obvious.

Version history
Last update:
‎07-19-2018 07:55 AM
Updated by: