Edit code with the Now Code Editor (advanced feature)
Summarize
Summary of Edit code with the Now Code Editor (advanced feature)
The Now Code Editor is an advanced, rich-text editor within the ServiceNow Zurich release that supports editing multiple code types including CSS, HTML, JavaScript, XML, and JSON. It enables ServiceNow customers to modify UI configurations, data resources, styles, events, and both client-side and server-side scripts directly within Next Experience UI Builder components.
Show less
Key Features
- Basic Editing: Includes code formatting with proper indentation, syntax highlighting, syntax error checking, toggle comments, word wrap, and a minimap for code overview.
- Auto-suggestions: Provides contextual suggestions for class names, functions, objects, and variables to speed up coding and reduce errors.
- Command Palette: Offers a searchable list of editor commands for common tasks like find and replace, folding code blocks, toggling comments, and more, accessible via keyboard shortcuts.
- Debugging: Integrated Script Debugger supports breakpoints, conditional breakpoints, and logpoints for JavaScript debugging with easy activation and management through the editor’s interface.
- Diff Mode: Allows side-by-side or inline comparison of code changes to review edits efficiently.
- Code Editor Macros: Provides reusable code snippets for common patterns such as loops, function templates, GlideSystem messages, comment blocks, and GlideRecord queries, streamlining script creation.
Practical Benefits for ServiceNow Customers
- Facilitates comprehensive and efficient code editing directly within ServiceNow’s UI Builder, enhancing customization capabilities.
- Improves code quality and reduces errors through syntax checking, formatting, and debugging tools.
- Speeds up development with helpful macros and auto-suggestions tailored to common ServiceNow scripting needs.
- Enhances developer productivity by integrating essential editing and debugging features into a unified editor experience with keyboard shortcuts.
Now Code Editor is a rich-text editor like interface that supports Cascading Style Sheets (CSS), Hypertext Markup Language (HTML), JavaScript, Extensible Markup Language (XML), and JavaScript Object Notation (JSON). Use Now Code Editor to modify UI configuration, data resource configuration, styles, events, client-side and server-side scripts in Next Experience UI Builder components.
- Basic editing
- Debugging
- Command palette
- Code formatting
- Syntax checking and highlighting
- Auto-suggestions
- Script macros for common code
Basic editing
| Action | Description |
|---|---|
| Format code |
Applies proper indentation to the script. Keyboard shortcut:
|
| Highlight syntax | Highlights the syntax of the code. |
| Check syntax |
Checks for formatting errors and highlights syntax errors.
|
| Show suggestions | Displays a list of valid elements at the insertion point such as:
Keyboard shortcut: You can also enable or turn off Syntax highlighting from the Settings menu.
|
| Toggle comments |
Comments one or more lines of code with two consecutive forward-slashes
//. Keyboard shortcut:
|
| Show minimap | Displays the minimap of the code snippet. You can display or hide the minimap option, from the Settings menu. |
| Enable word wrap | Enables word wrap function in the editor area. You can toggle the Enable word wrap option from the Settings menu. |
| Show command palette | Displays a list of available commands for the common operations. You can
execute editor commands, find and replace text, fold and unfold code blocks,
toggle comments and many more tasks using the same interactive window.
Keyboard shortcut
|
| Expand editor |
Expands or collapses the editor. Keyboard shortcut
|
Debugging
| Task | Do this |
|---|---|
| Add breakpoint | Right-click beside a line number in the ruler area and select Add breakpoint. |
| Add conditional breakpoint |
|
| Add logpoint | Right-click beside a line number in the ruler area and select Add logpoint. |
| Compare text in Diff mode |
Use the side-by-side view icon |
Code editor macros
- for
- Description: Inserts a standard for loop with an example array.
- Output:
for (var i=0; i< myArray.length; i++) { //myArray[i]; }
- method
- Description: Inserts an empty JavaScript function template.
- Output:
/*_________________________________________________________________ * Description: * Parameters: * Returns: ________________________________________________________________*/ : function() { },
- info
- Description: Inserts a GlideSystem information message.
- Output:
gs.addInfoMessage(gs.getMessage(""));
- doc
- Description: Inserts a comment block for describing a function or parameters.
- Output:
/** * Description: * Parameters: * Returns: */
- vargror
- Description: Inserts a GlideRecord query for two values with an OR condition.
- Output:
var gr = new GlideRecord(''); var qc = gr.addQuery('field', 'value1'); qc.addOrCondition('field', 'value2'); gr.query(); while (gr.next()) { }
- vargr
- Description: Inserts a standard GlideRecord query for a single value.
- Output:
var gr = new GlideRecord(""); gr.addQuery("name", "value"); gr.query(); if (gr.next()) { }