← Tools from Everyday Project Work
AI Assisted · ServiceNow Form Utility

Code Editor Popup

A real code editor for plain text fields on classic ServiceNow forms. Syntax highlighting, formatting and SQL safety checks, switched on per field with one dictionary attribute.

What It Does

SQL queries, JSON, scripts or HTML often live in plain multi-line text fields. Editing them in a bare textarea means no highlighting, no indentation and no help when something is wrong.

Code Editor Popup adds a small Edit SQL or Edit code button below every field you choose. It opens a popup with CodeMirror 6, the editor behind many modern browser IDEs. Take over writes the text back into the field, the form is saved as usual.

  • Configured, not coded: add code_editor=sql:tsql to the dictionary attributes of a field. One global script finds every configured field on any table.
  • Languages: SQL with dialects (T-SQL / SQL Server by default, MySQL, MariaDB, PostgreSQL, Oracle PL/SQL, SQLite, standard SQL), JavaScript, TypeScript, JSON, HTML, XML, CSS and Java.
  • Editor comfort: line numbers, auto-indent, bracket matching, code folding, search and replace, multiple cursors, undo, fullscreen.
  • Format and Compact: dialect-aware SQL formatting, beautifier for JavaScript, HTML, CSS and XML, pretty JSON. Compact puts a SQL statement on one line.
  • SQL safety checks: warnings for DELETE or UPDATE without WHERE, DROP, TRUNCATE and SELECT *. Click a warning to jump to the line.
  • Placeholders stand out: ${var}, @param, :param and ? are highlighted.
  • Read-only aware: read-only fields open in a view mode without Take over.
  • Keyboard first: Ctrl+Enter takes the text over, Esc cancels.

Everything runs on the instance. CodeMirror 6, sql-formatter and js-beautify (all MIT licensed) are bundled once and stored as UI Scripts, so nothing is loaded from a CDN. That keeps it working in locked-down customer instances. In the global scope: one client script, one script include, one UI page and four UI scripts.

Free to use. You are welcome to use and adapt this tool in your own projects. It is shared as is, without warranty or support, so please try it on a sub-production instance first. Using it is at your own risk.

A Closer Look

Click a screenshot to open it at full size.

ServiceNow form with a SQL query field and the Edit SQL button below it
One Button per FieldEvery field with the code_editor attribute gets its own Edit button.
Code editor popup with highlighted T-SQL and three warnings
Highlighting and WarningsT-SQL highlighting, placeholders and warnings for risky statements.
The same query after Format, neatly indented
FormatOne click turns a one-liner into a readable, indented query.
Search and replace panel with matches highlighted
Search and ReplaceWith match case, regular expressions and whole words.

Live Demo

The same editor as on the instance, running right here in your browser. Nothing is sent anywhere.

The first click loads about 1.8 MB of JavaScript. Try Format, Ctrl+F and Ctrl+Enter.

Getting Started

  1. Download the update set XML below.
  2. In your instance, open System Update Sets > Retrieved Update Sets and choose Import Update Set from XML.
  3. Open the imported update set "Code Editor Popup", preview it and commit it.
  4. Add code_editor=sql:tsql (or json, javascript, html, …) to the attributes of a multi-line text field in its dictionary entry.
  5. Open a record of that table in the classic UI: the Edit button is below the field.

Download Code Editor Popup

One update set with seven records (client script, script include, UI page and four UI scripts), global scope, about 2 MB including the bundled libraries.

Download Update Set (XML)

Classic UI16 forms only. Free to use, at your own risk. Please install it on a sub-production instance first. Bundled libraries: CodeMirror 6, sql-formatter and js-beautify, all under the MIT licence.

Questions about this tool? Contact Markus.