
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
08-25-2019 06:23 AM - edited 08-10-2024 08:16 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Probably you've heard of them or are even using them: Syntax Editor Macros. Macros which help you speed up coding. Macros which with you can easily get your hands on (short) example parts of code. It's been in ServiceNow already for ages, and several articles or threads can be found on the Community. The articles though, al about how it works out-of-the-box. Not about expanding them! And looking at several customer Instances, this nice piece of art in ServiceNow is still not that common for developers.
By expanding the Syntax Editor Macros, you could really speed up your development!
How it works
A short recap, and also some articles listed below which explain the out-of-the-box working of the Syntax Editor Macros.
Basically, when you are in a script field - which if of type script - you will have the Script Editor available. Within the Script Editor, you could just type the name of one of the Syntax Editor Macros and hit the <TAB> key. The code is generated for you.
The available out-of-the-box Syntax Editor Macros:
Also read about this in the below articles:
Syntax editor macros... a tiny thing that makes the developer life a lot easier
Is it possible to become faster with no quality loss?
"Syntax Editor Macros" - Write a generic script faster
Obviously, you are free to use other solutions which might offer similar functionality. Other solutions like Visual Studio Code, Quick Text Paste. Though, we are focussing here on the out-of-the-box Syntax Macro Editors.
Need to know
- Using the generating of the code in the Syntax Macro Editors available will only work on the Platform UI on fields of type Script. A field which just is named "script" is not enough! For example: if you create a new Syntax Macro Editor record, there is a script field without the Script Editor. It won't work there.
- Non-script type fields can contain the Script Editor. Though, on for example XML type fields, the Syntax Marco Editors won't work either.
- On the Service Portal Widget Editor these Syntax Macro Editors won't work! There's a technical workaround available for this to get this working (Service Portal: Syntax Editor Macros). An other workaround would be to edit the Service Portal widget from within the Platform UI.
- Like the Service Portal Widget Editor, these Syntax Macro Editors also won't work on the Virtual Agent Designer. Haven't found a workaround for this yet so if anyone knows… let me know!
Expanding the Syntax Editor Macros
During your ServiceNow journey, you will come across code which you are using very often. For example, a GlideAggregate query, or GlideAjax calls, anonymous functions, switch operators, etc., etc., etc..
You could stick with the out-of-the-box Syntax Editor Macros, or… create your own!
So let's start expanding the Syntax Editor Macros en speed up your development. Besides speeding up your development, it also helps in building more generic code, making less typos, etc..
Do note: still you have to edit the generated code. For example, leaving "gr" naming is really poor development.
Creating your own Syntax Editor Macro is quite simple. Navigate to the Syntax Editor Macros and hit the New button, enter a name for the Macro, enter the text (your actual code), and that's it.
With this example, you could type in any script field "count", hit the <TAB> key and you've got your example code for a GlideAggregate query generated!
The Syntax Editor Macros we use
Attached an XML with all the Syntax Editor Macros we use. A short sumup of these:
- Ajax call (ajax)
- GlideAggregate query (count)
- GlideRecord with encoded query (encoded)
- For loop (for)
- Anonymous function (function)
- GlideRecord with get (get)
- Insert of a GlideRecord (insert)
- Regulare GlideRecord query (query)
- Switch operator (switch)
- Update of GlideRecord (update)
- While loop (while)
---
And that's it actually! Not that much too it.
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 3,092 Views