Script API
This content is intended for advanced Studio users.
Script API is a JavaScript API that runs inside a form at defined trigger points. It gives you direct programmatic control over form data and behaviour — going beyond what the dependency system and expression language can express. This page introduces the Script API in the context of data connectivity. The full method reference is in the Advanced section.
What Script API is
Script API exposes a set of JavaScript methods you can call inside scripts attached to a form. Scripts run in the browser, within the form session, when a defined trigger fires. Examples of this would be a field value change, a page load, or form submission.
Using the Script API, you can:
- Read and set the values of form fields and variables programmatically
- Trigger data connectors manually and handle the results
- Apply logic that spans multiple fields or pages in response to a single event
- Implement custom validation or transformation that the expression language does not support
How Script API differs from JavaScript views
These two tools operate at different points in the data flow:
| JavaScript views | Script API | |
|---|---|---|
| Runs on | EHR server | Browser (inside the form) |
| Purpose | Query and transform data before it reaches the form | Respond to user interactions and control form behaviour at runtime |
| Trigger | Called by a data connector | Fires on form events (field change, page load, submit) |
| Requires | AQL + JavaScript | JavaScript |
| Use when | You need to combine or reshape EHR data | You need to react to user input or control multiple fields programmatically |
In practice, both tools are often used together: a JavaScript view fetches and reshapes the data, and Script API handles what happens in the form when that data arrives or when the user takes an action.
When to use Script API
Use Script API when:
- You need to implement conditional logic that the dependency and expression systems cannot express.
- You need to intercept or validate data before submission.
For most data-binding scenarios like pre-populating a field from an AQL view, or filtering a list based on another field, a data connector with standard configuration is sufficient without scripting. Reserve Script API for cases where the standard tools cannot meet the requirement.
Where to find Script APIs
Scripts are written in the Script editor panel in Form builder, accessed from the bottom toolbar. The editor provides syntax highlighting and access to available ScriptAPI methods. The full Script API references, including all available methods, their parameters, return values, and worked examples are in the Advanced: Script API section.
Frequently asked questions (FAQs)
What is Script API?
Script API is a JavaScript API that runs inside a form at defined trigger points — for example, when a field value changes, when a page loads, or when the form is submitted. It gives you programmatic control over form behaviour and data from within the form itself.
How does Script API differ from JavaScript views?
JavaScript views run on the EHR server and are used to query and transform data before it reaches the form. Script API runs inside the form in the browser and is used to respond to user interactions, set field values, call data connectors, or apply custom logic at runtime.
When should I use Script API instead of dependencies or expressions?
Use Script API when the dependency system or expression language cannot handle what you need. Examples of use: Setting multiple field values from a single trigger, calling an external data source based on a user action, or implementing complex conditional logic.
Where is the full Script API reference?
The full method reference, including all available ScriptAPI methods, parameters, and code examples, is in the Advanced: Script API section.