Syntax editor JavaScript support

  • Release version: Xanadu
  • Updated August 1, 2024
  • 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 Syntax editor JavaScript support

    The Syntax Editor in ServiceNow provides comprehensive editing capabilities tailored for JavaScript scripts. It enhances the coding experience by offering features such as syntax checking, code formatting, commenting, searching, and full-screen editing. These functions streamline script creation and maintenance, improving accuracy and efficiency.

    Show full answer Show less

    Key Features

    • Toggle Syntax Editor: Enable or disable the syntax editor for script fields.
    • Format Code: Automatically applies proper indentation to your JavaScript code.
    • Comment/Uncomment Selected Code: Quickly comment out or remove comments from selected lines.
    • Check Syntax: Automatically checks scripts for syntax errors as you type, highlighting issues inline.
    • Search and Replace: Supports searching using regular expressions, finding next/previous matches, and replacing single or all occurrences within the script.
    • Save: Save script changes without leaving the editor, especially useful in full-screen mode.
    • Toggle Full Screen Mode: Expand the script editing area to full form view for easier editing (not supported in Internet Explorer).
    • Keyboard Shortcuts: Numerous shortcuts are available for all editing functions, accessible via an in-editor help screen.

    Editing Tips

    • Fold and unfold code blocks using the plus/minus icons beside foldable code sections.
    • Use Tab and Shift + Tab keys to indent or reduce indentation of lines or selected code blocks.
    • Insert fixed spaces with the Tab key to maintain consistent formatting.

    JavaScript Standards and Resources

    Scripts in ServiceNow use the ECMA 262 standard JavaScript. For further learning or reference, customers can consult authoritative resources such as the Mozilla Developer Network, the official ECMA standard documentation, and other JavaScript reference materials. These resources help ensure scripts are compliant with industry standards and best practices.

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

    JavaScript editing functions

    Icon Keyboard Shortcut Name Description
    N/A Toggle Syntax Editor Disables the syntax editor. Click the button again to enable the syntax editor.
    Access Key + R Format Code Applies the proper indentation to the script.
    Access Key + C Comment Selected Code Comments out the selected code.
    Access Key + U Uncomment Selected Code Removes comment codes from the selected code.
    N/A 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.
    Access Key + \ 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.
    Access Key + [ Find Next Locates the next occurrence of the current search term in the script field. Use Start Searching to change the current search term.
    Access Key + ] Find Previous Locates the previous occurrence of the current search term in the script field. Use Start Searching to change the current search term.
    Access Key + W 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.
    Access Key + ; 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.
    N/A Save Saves changes without leaving the current view. Use this button in full screen mode to save without returning to standard form view.
    Access Key + L 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.
    Access Key + P 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: