LinkScript

Introduction

A LinkScript is a named, reusable Groovy script that can be chained with other LinkScripts to build composable processing pipelines. Each LinkScript exposes a body of Groovy code and a set of arcs that wire its result into (or out of) other LinkScripts. This lets you decompose a complex computation into small, independently testable scripts and connect them into a dependency graph instead of duplicating logic across many tasks, actions, and listeners.

LinkScripts are evaluated by name through LinkScriptService.run(name, bindings) and are cached for reuse, so the same script can be invoked from many places with different input bindings.

Access

Navigate to: Studio > LinkScript.

The menu entry (studio-link-script) is available under the Studio application root.

LinkScript grid

The grid lists existing LinkScripts. Each row provides a Test button (play icon) to run the script directly from the list.

Creating a LinkScript

LinkScript form

A LinkScript is defined by the following fields:

Field Required Description

Name

Yes

Unique name used to invoke the LinkScript. It is the identifier under which the script is registered and called by LinkScriptService.run().

Transactional

No

When enabled (boolean switch), the LinkScript execution runs inside a transaction. Defaults to false.

Description

No

Free-text HTML description of the script’s purpose.

Body

Yes

The Groovy script body (see Body).

Body

LinkScript body editor

The Body tab holds the Groovy code, edited in a syntax-highlighted code editor.

If you do not add a return on the last line of the body, all variables of the current context plus all variables you defined in the body are implicitly returned. Whether returned implicitly or explicitly, the value is injected into the context under the name defined in the arc.

Arcs

LinkScripts are connected to one another through arcs. Each arc points from one LinkScript to another and carries an optional condition. Two arc collections are available on the form, each shown as a related grid:

  • Dependency arcs — LinkScripts that must be evaluated before this one. Their results are made available as bindings in this script’s body.

  • Output arcs — LinkScripts that consume this script’s result.

LinkScript dependency arcs

Each arc row has the following fields:

Field Description

Name

The binding name under which the target LinkScript’s result is injected. Must match the pattern ^[a-z][a-zA-Z0-9]*$ (starts with a lowercase letter, alphanumeric). Defaults to result.

Condition

An optional Groovy condition. When present, the arc is only followed if the condition evaluates to true.

To LinkScript

The target LinkScript the arc points to. A new LinkScript can be created inline from this field.

Arcs are ordered by Sequence and can be reordered in the grid.

Testing a LinkScript

Click the Test button (in the grid or the form toolbar) to open the test popup.

LinkScript test popup

In the popup you provide the bindings the script expects as a list of parameter/expression pairs:

  • The Parameter is the binding name used inside the script body.

  • The Expression is evaluated as a Groovy expression if it starts with eval:; otherwise it is treated as a plain string.

The bindings the script can accept are detected automatically from the body when the popup opens (via LinkScriptController.setBindings()), so the parameter rows are pre-populated with the script’s dynamic variables.

Click Test in the popup to run the LinkScript. The result is returned and displayed as an info message.

Technical Details

Entities

Field Type Description

name

String (required, unique)

Invocation name of the LinkScript

transactional

Boolean (default: false)

Whether the script runs within a transaction

description

Large String

HTML description

body

Large String (required)

The Groovy script body

outputArcs

O2M: LinkScriptArc

Arcs whose outputLinkScript is this script

dependencyArcs

O2M: LinkScriptArc

Arcs whose dependencyLinkScript is this script

The LinkScriptArc entity holds sequence, name, conditionScript, and a required toLinkScript (target). LinkScriptBinding is a non-persistable helper entity (parameter / expression) used by the test popup.

Backend Services

  • LinkScriptService — Entry point; run(name, bindings) resolves the LinkScript by name and evaluates it, returning a LinkScriptResult.

  • LinkScriptServiceImpl — Core evaluation logic, including arc traversal and binding injection.

  • LinkScriptBindingsService / LinkScriptBindingsServiceImpl — Build the binding set passed to the script.

  • LinkScriptGroovyEvaluator / LinkScriptEvaluator — Evaluate the Groovy body; LinkScriptGroovyScriptHelper analyzes the script to detect dynamic variables.

  • LinkScriptCacheLoader — Caches compiled LinkScripts for reuse.

  • LinkScriptController — Form actions: setBindings() (detect bindings for the test popup) and run() (execute and report the result).

The package root is com.axelor.studio.ls.