Using the JavaScript syntax editor

  • Release version: Zurich
  • Updated March 12, 2026
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Using the JavaScript syntax editor

    The JavaScript syntax editor in ServiceNow offers comprehensive editing tools designed to facilitate writing and managing JavaScript scripts within the platform. It supports automatic syntax checking, code formatting, and search and replace functionality, enhancing script development efficiency and accuracy.

    Show full answer Show less

    Key Features

    • Toggle Syntax Editor: Enables or disables the enhanced syntax editor interface.
    • Format Code: Automatically applies proper indentation to scripts for improved readability.
    • Comment/Uncomment Selected Code: Allows quick commenting or uncommenting of selected code lines.
    • Check Syntax: Automatically and manually checks scripts for syntax errors, highlighting issues inline for easy identification.
    • Search Functions: Includes Start Searching (with support for regular expressions), Find Next, Find Previous, Replace, and Replace All, streamlining code navigation and editing.
    • Save: Saves changes without exiting the syntax editor, particularly useful in full screen mode.
    • Toggle Full Screen Mode: Expands the script field to occupy the full form view for easier editing (not supported in Internet Explorer).
    • Help: Displays keyboard shortcuts and editor help for efficient script writing.
    • Code Folding: Enables collapsing and expanding of code blocks to improve script readability and navigation.
    • Indentation Controls: Supports tab-based indentation and unindentation both for single lines and selected blocks of code using Tab and Shift + Tab keys.
    • Macros: Provides shortcuts for commonly used code snippets, inserted by typing a macro keyword followed by Tab.
    • Context Menu: Offers contextual options for script includes, Glide APIs, and tables within the editor.

    Practical Use and Benefits

    ServiceNow customers can leverage the JavaScript syntax editor to write, debug, and maintain scripts more effectively within the platform. The automatic syntax checking reduces the risk of introducing errors, while code formatting and folding improve script clarity. Search and replace functionalities, including support for regular expressions, accelerate code updates. Full screen mode and macros make editing more efficient, especially for complex scripts.

    By utilizing these features, developers can produce higher quality scripts with less effort, ultimately improving application stability and performance.

    Additional Resources

    The editor supports ECMA 262 standard JavaScript. Customers seeking to deepen their JavaScript knowledge can refer to authoritative resources such as Mozilla's JavaScript documentation, the official ECMA standard, and related historical and technical references.

    The syntax editor provides editing functions to support editing JavaScript scripts.

    JavaScript editing functions

    Name Description
    Toggle Syntax Editor Disables the syntax editor. Click the button again to enable the syntax editor.
    Format Code Applies the proper indentation to the script.
    Comment Selected Code Comments out the selected code.
    Uncomment Selected Code Removes comment codes from the selected code.
    Check Syntax Checks the code for syntax errors. By default, the system automatically checks for syntax errors as you type in a script field. If an error or warning is found, the syntax editor displays a bullet beside the script line containing the error or warning. This check occurs on all script fields.
    Start Searching Highlights all occurrences of a search term in the script field and locates the first occurrence. Click the icon, then enter the search term and press Enter. You can use regular expressions enclosed in slashes to define the search term. For example, the term /a{3}/ locates aaa.
    Find Next Locates the next occurrence of the current search term in the script field. Use Start Searching to change the current search term.
    Find Previous Locates the previous occurrence of the current search term in the script field. Use Start Searching to change the current search term.
    Replace Replaces the next occurrence of a text string in the script field.
    1. Click the icon, then enter the string to replace and press Enter. You can use regular expressions enclosed in slashes to define the string to replace. For example, the term /a{3}/ locates aaa.
    2. Enter the replacement string and press Enter.
    Replace All Replaces all occurrences of a text string in the script field.
    1. Click the icon, then enter the string to replace and press Enter. You can use regular expressions enclosed in slashes to define the string to replace. For example, the term /a{3}/ locates aaa.
    2. Enter the replacement string and press Enter.
    Save Saves changes without leaving the current view. Use this button in full screen mode to save without returning to standard form view.
    Toggle Full Screen Mode Expands the script field to use the full form view for easier editing. Click the button again to return to standard form view. This feature is not available for Internet Explorer.
    Help Displays the keyboard shortcuts help screen.

    JavaScript editing tips

    • To fold a code block, click the minus sign beside the first line of the block. The minus sign only appears beside blocks that can be folded. To unfold the code block, click the plus sign.
    • To insert a fixed space anywhere in your code, press Tab.
    • To indent a single line of code, click in the leading white space of the line and then press Tab.
    • To indent one or more lines of code, select the code and then press Tab. To decrease the indentation, press Shift + Tab.
    • To remove one tab from the start of a line of code, click in the line and press Shift + Tab.

    JavaScript resources

    Scripts use ECMA 262 standard JavaScript. Helpful resources include: