Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

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:

Syntax editor macro.GIF

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.

Syntax editor macro 2.GIF

If you type vargr and press "TAB" in a script editor this 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");

gr.query();

if (gr.next()) {

   

}

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" in the script editor 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.

Sadly these won't work in the "Script - Background" thou since it isn't a "true" script editor field. But why shouldn't it be   in the future 😃

Anyway, I hope this will help some developers out there stop having to retype the same code over and over again.

//Göran

6 Comments