The AMSX Programming Language
AMSX (Asset Management Script eXecution) is xAssets' proprietary server-side scripting language for writing data transformation and integration scripts. This page provides an overview of AMSX capabilities and basic syntax. For the complete command reference, contact xAssets support or refer to the xAssets Programmers Guide.
Prerequisites
- Familiarity with the Transformation Editor and transformation concepts
- Understanding of SQL basics for database operations
- Configuration-level access to create or edit transformations with AMSX scripts
Purpose
AMSX enables administrators and integrators to:
- Query and manipulate database records using SQL
- Import and export data via HTTP, CSV, XML, and JSON
- Automate Active Directory, Azure, Intune, and other integrations
- Create and update xAssets configuration (forms, queries, menus) using XDML blocks
- Run scheduled batch operations via the xAssets Batch Service
- Chain multiple operations together in a single script
Where AMSX Scripts Run
| Location | Description |
|---|---|
| Transformation editor | Scripts are embedded in the SourceQuery field of a transformation, using the "AMSX Script" source type |
| Scheduled batch jobs | Run automatically via the xAssets Batch Service at configured intervals |
| Menu items | Triggered by users from the xAssets menu |
| REST API | Executed via the REST API for external automation |
| Standalone files | Stored as .amsx files in the AMSX scripts folder |
Basic Syntax
AMSX is a command-per-line language. Each line is a command. Variables are referenced using %variable% syntax.
// Assign a variable
Set myvar = "Hello World"
// Query the database
Set count = Sql "SELECT count(*) FROM Asset"
// Use the variable
Set result = "There are %count% assets"
Comments
Lines starting with // are comments and are ignored during execution.
Variables
Variables are assigned with Set and referenced with %name%:
Set name = "Server Room"
Set id = Sql "SELECT LocationID FROM Location WHERE LocationName = '%name%'"
Key built-in variables:
| Variable | Purpose |
|---|---|
%result% |
Output buffer for API responses |
%text% |
Content collected by TEXT/ENDTEXT blocks |
%forvariable% |
Current iteration value in ForEach loops |
Control Flow
IF Statements
If %count% > 0 Then
Set result = "%count% records found"
Else
Set result = "No records"
End If
Conditions can include SQL expressions:
If exists(select 1 from Asset where CategoryID = 10) Then
Set result = "Licenses exist"
End If
FOR Loops
Numeric loops iterate through a range:
For i = 1 to 10 step 1
Set x = Sql "SELECT AssetDesc FROM Asset WHERE AssetID = %i%"
Next
ForEach (Row Iteration)
Process each row from a SQL query result set:
ForEach "SELECT AssetID, AssetDesc FROM Asset WHERE CategoryID = 1"
Set desc = %AssetDesc%
// Process each row
EndEach
Inside a ForEach block, each column from the query result is available as a %ColumnName% variable.
SQL Operations
Reading Data
Read a single value from the database:
Set value = Sql "SELECT FieldName FROM Table WHERE ID = 1"
Executing SQL
Execute an update, insert, or delete statement:
SqlExecute "UPDATE Asset SET StatusID = 2 WHERE AssetID = %id%"
Multi-line SQL with TEXT Blocks
Use TEXT/ENDTEXT blocks for long SQL statements:
TEXT
SELECT a.AssetID, a.AssetDesc, l.LocationName
FROM Asset a
JOIN Location l ON a.LocationID = l.LocationID
WHERE a.CategoryID = 1
ENDTEXT
ExecuteText
Use TEXTEVALUATE / ENDTEXTEVALUATE when you need %variable% substitution within the text block.
HTTP Operations
AMSX can make HTTP requests for API integrations:
Set response = HttpSendNet "https://api.example.com/data", "application/json", ""
The full syntax supports authentication, HTTP method selection (GET, POST, PUT), and custom headers. This is used extensively by the built-in integrations for Azure, Intune, OKTA, and other cloud services.
XDML Data Deployment
AMSX can create and update xAssets configuration objects using XDML blocks. This is the primary mechanism for deploying configuration between environments:
// Create a location
Location
LocationName: London Office
LocationAddress1: 123 High Street
END Location
// Create a query with fields
Query
SavedSelectName: My Custom Report
Type: SYSTEM
SecurityCode: PUBLIC
SubjectID: 1 : Assets
Query Field
FieldName: AssetDesc
DisplayName: Description
FieldWidth: 240
FieldPosition: 1
END Query Field
END Query
To update existing records, include the ID field. Records are matched by name if no ID is specified.
Running Other Transformations
Call other transformations from within an AMSX script:
RunTransform "Active Directory Import"
This allows you to build complex multi-step processes by chaining transformations together.
Common Use Cases
| Use Case | Typical Commands |
|---|---|
| Data import from CSV/Excel | ForEach with SQL inserts |
| Active Directory sync | HttpSendNet to Graph API + ForEach row processing |
| Scheduled reports | SQL queries + email output |
| Configuration deployment | XDML blocks for forms, queries, menus |
| Data cleanup | ForEach + SqlExecute for bulk updates |
Tip: AMSX is a powerful language, but for simple data imports that just map source fields to destination fields, the standard transformation mapping UI (see Source to Destination Data Mapping) is simpler and easier to maintain. Use AMSX when you need conditional logic, HTTP calls, multi-step processing, or operations that cannot be expressed through field mapping alone.
Related Articles
- XCS Client Scripting — client-side scripting for form behaviour (complementary to AMSX)
- Transformation Data Sources — selecting AMSX as the source type
- Editing a Transformation — the Transformation Editor where scripts are entered