Zoomed Image

Code Editor

xAssets Configuration Guide
Integration and Data Operations with Transformations

Code Editor

This page describes the built-in code editor in xAssets, which provides syntax highlighting and editing features for the three xAssets scripting languages: AMSX, XCS, and XDSL. The code editor appears throughout the application wherever scripts or configuration code are authored.

Prerequisites

  • Configuration-level access to areas that contain script editing (transformations, XCS scripts, discovery scripts)
  • A modern web browser with JavaScript enabled

Where the Code Editor Appears

The code editor is used in the following contexts:

Context Language How to Access
Transformation editor (SourceQuery field) AMSX Admin > Transformations > edit a transformation with source type "AMSX Script"
XCS client script editor XCS Admin > Forms > edit a form > XCS tab, or Admin > XCS Scripts
Discovery script editor XDSL Discovery configuration screens
AMSX standalone files AMSX When editing .amsx files from the AMSX scripts list

Syntax Highlighting

The code editor automatically detects the scripting language and applies colour-coded syntax highlighting to improve readability:

AMSX Highlighting

Element Colour Examples
Keywords Blue Set, If, Then, Else, End If, For, Next, ForEach, EndEach
SQL keywords Purple SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, JOIN
String literals Green "Hello World", 'single quoted'
Comments Grey // This is a comment
Variables Orange %variablename%
Commands Dark blue Sql, SqlExecute, HttpSendNet, RunTransform, Text, EndText

XCS Highlighting

Element Colour Examples
Keywords Blue If, Then, Else, End If, Dim, Set, Function, Sub
String literals Green "text value"
Comments Grey ' This is a comment (single-quote comment style)
Built-in objects Dark blue Field, Form, Dialog, MsgBox
Operators Red =, <>, >, <, And, Or, Not

XDSL Highlighting

Element Colour Examples
Commands Blue Discovery-specific commands and directives
Parameters Orange Named parameters and their values
Comments Grey Comment lines
String literals Green Quoted string values

Editor Features

The code editor provides the following productivity features beyond basic text editing:

Line Numbers

Line numbers are displayed in a gutter on the left side of the editor. These are referenced in error messages when a script fails, making it easy to locate the problem line.

Automatic Indentation

When you press Enter after a block-opening statement (such as If, For, ForEach, or Sub), the editor automatically indents the next line. This helps maintain readable code structure.

Tab Support

Pressing Tab inserts spaces (not a tab character) for consistent indentation. The default indent width aligns with the language conventions.

Text Selection and Operations

Standard text editing operations are supported:

Operation Shortcut
Select all Ctrl+A
Copy Ctrl+C
Paste Ctrl+V
Undo Ctrl+Z
Redo Ctrl+Y
Find Ctrl+F (where supported by the editor control)

Large Script Support

The editor handles scripts of several thousand lines without performance degradation. For very large scripts, consider breaking the logic into multiple transformations called via RunTransform for maintainability.

Tips for Effective Script Editing

  • Use comments liberally. AMSX uses // for comments; XCS uses ' (single quote). Document the purpose of each section.
  • Indent consistently. Although indentation is not syntactically significant in AMSX or XCS, consistent indentation makes scripts far easier to read and debug.
  • Test incrementally. Write and test small sections of a script at a time. Use the xacli command-line tool to test AMSX scripts outside the web editor:
    xacli amsx "Set x = Sql \"SELECT count(*) FROM Asset\""
    
  • Keep scripts focused. A single transformation should do one job. Use RunTransform to chain multiple operations.
  • Back up scripts. Before making significant changes to a working script, copy the original to a text file or use the XCSLoad file synchronisation feature to maintain a file-based copy.

Error Reporting

When a script has a runtime error, the error message typically includes:

  • The line number where the error occurred
  • A description of the error (e.g., "SQL syntax error", "Variable not defined", "HTTP request failed")
  • For SQL errors, the offending SQL statement

The line numbers in error messages correspond to the line numbers shown in the editor gutter, making it straightforward to locate and fix issues.

Limitations

  • The code editor does not provide IntelliSense or auto-completion. You must know the command names and syntax for the language you are using.
  • There is no built-in debugger with breakpoints or stepping. Use Set result = ... (AMSX) or diagnostic output to trace execution.
  • The editor does not perform syntax validation before saving. Scripts are validated at runtime when executed.