Using the JavaScript syntax editor
Summarize
Summary of Using the JavaScript syntax editor
The JavaScript syntax editor in ServiceNow Australia release offers robust editing features to efficiently write and manage JavaScript scripts. It supports syntax checking, code formatting, commenting, searching, replacing, saving, and full-screen editing to enhance script development directly within the platform.
Show less
Key Features
- Toggle Syntax Editor: Enable or disable the syntax editor to suit editing preferences.
- Format Code: Automatically applies proper indentation for clearer code structure.
- Comment/Uncomment Selected Code: Quickly toggle comments on selected script lines.
- Check Syntax: Real-time syntax error detection with visual indicators beside faulty lines.
- Search and Replace: Supports searching with regular expressions, finding next/previous occurrences, and replacing one or all matches within the script field.
- Save: Save script changes without leaving the current editing view, especially useful in full-screen mode.
- Toggle Full Screen Mode: Expand the script editor to fill the form view for easier editing (not supported in Internet Explorer).
- Help: Access keyboard shortcut help for efficient coding.
- Code Folding: Collapse and expand code blocks for better navigation.
- Indentation Controls: Use Tab and Shift+Tab to increase or decrease code indentation on single or multiple lines.
- Syntax Editor Macros: Insert common code snippets by typing macro keywords followed by Tab.
- Context Menu: Access context-specific options for script includes, Glide APIs, and tables within the editor.
Practical Use and Benefits
This editor helps ServiceNow customers write cleaner, error-free JavaScript by providing immediate feedback on syntax errors and convenient editing tools. Features like search-and-replace with regex, code folding, and macros streamline script writing and maintenance. Full-screen editing and easy saving improve the user experience when working on complex scripts. Overall, it enhances productivity and reduces debugging time when customizing ServiceNow applications.
Additional Resources
Scripts conform to the ECMA 262 JavaScript standard. Customers can refer to trusted JavaScript documentation such as Mozilla Developer Network and the ECMA standard PDF for deeper understanding and best practices.
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.
|
| Replace All | Replaces all occurrences of a text string in the script field.
|
| 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:
- Mozilla: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference
- ECMA Standard in PDF format: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
- History and overview: http://javascript.crockford.com/survey.html
- JavaScript number reference: http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference