logo

NJP

Syntax Editor : Introduction

Import · May 01, 2020 · article

Definitions:

The Syntax Editor(SE) is a ServiceNow built-in text editor. It offers the following features as you script:

  • Automatic Javascript syntax coloring, auto-indentation, line numbers, and creation of closing braces and quotes.
  • Code Editing functions
  • Context-sensitive Help
  • Syntax Error Checking
  • Editor Macros for typing commonly used code

Color Coding:

As a developer, we understand the importance of color-coding. It enhances the code reading experience. So, in SE we have following color codes:

  • Blue for strings or reserved keywords(can't choose it as a variable name)
  • Purple for Javascript commands(tells the platform what to do)
  • Green comments(Comments help you or other people understand code better)
  • Bold text indicates the context menu item.image

See the color codes in the example.

Braces and Quotes:

As we type the code in SE, the closing parenthesis, braces or quote are automatically inserted and you can also check the matching character while placing the cursor beside the parenthesis, braces or quote.

image

Context-Sensitive Help

While editing a script, Context-Sensitive Help can be invoked by using the CTRL+ Space (both Mac/Windows) or a .(period)

image

Note: Suggestions are context-sensitive relative to the cursor's current position and are filtered based on API type. So if you are working on a server-side script like BR you will see suggestions from server-side APIs only.

Properties assigned to a locally declared object are also included in the suggestions for example:

If I have an object called car that has attributes like the model, capacity, make, so when I type car. I will get the attributes in the suggestion.

Context Menu Options:

In the syntax editor, bold font is used for tokens that have a context menu. Right-click the token to view context menu options. If you use a Mac, you can use the Command-click shortcut.

image

Code Editing Functions:

SE toolbar provides standard JavaScript code editing functions:

image

image

Just explore each one of them and trust me once you are habitual of using these tricks you will certainly have better efficiency.

REQUEST:

If you find the article helpful, please mark the article as helpful, and since it has lots of useful links do remember to bookmark this article.

In case you need any help, please do connect with me. It will be my pleasure to help you.

Happy Learning Guys!!!

----->Dhruv Gupta

View original source

https://www.servicenow.com/community/developer-articles/syntax-editor-introduction/ta-p/2320840