fredag 8 januari 2016

Syntax editor macros... a tiny thing that makes the developer life a lot easier

This is one of the little things that I learned about when I went to the ServiceNow scripting course. And if I hadn't gone the course, I can promise you I would never have known about it.

Here is where you can find it:

System Definition->Syntax Editor Macros

As you probably have noticed, much of the code that you write is repeatable and are the same over and over again in different places. Now these macros are here to make your life a lot easier. There are a few OOB and you can easy add your own. Just remember that the macros you create isn't personal, everyone on the instance who have credentials to edit a script editor, will be able to use the macros.

So what do they do?

If we look at the OOB ones there is for example a macro called vargr. If you type vargr and press "TAB" the editor will replace "vargr"  with the code that is inside the field "text" in the macro record.
For this example it will put:

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

You won't see the $0. This is a variable for the script to know where to put the marker.

If you type "help" and press "TAB" you will see a list over every macro there is to use and as well the text that is in the comment field on each macro.

Like this:

The Syntax Editor macros are:
doc - Documentation Header
for - Standard loop for arrays
vargror - Example GlideRecord Or Query
info -
method - Standard JavaScript Class Method
vargr - A common pattern of creating and querying a GlideRecord

As you can see there isn't any text after "info" and that is because there isn't any text in comment field  on that macro.

Hopefully this can make your days a bit more effective and little less boring =)

Inga kommentarer:

Skicka en kommentar