> For the complete documentation index, see [llms.txt](https://developer.vario-software.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.vario-software.de/documentation/scripting/script-modules.md).

# Script Modules

Reusable JavaScript modules shared across workflows and batch scripts.

VARIO Cloud Script Modules are reusable JavaScript files stored directly in the ERP. Instead of duplicating logic across workflows and batch scripts, you write it once as a module and import it wherever needed. Modules are managed under **System → Scripts** in VARIO Cloud.

***

## Module Groups

Groups organize modules into named collections. Every group has a unique `name` and an optional `description`.

A module can belong to exactly one group or exist ungrouped at the top level.

***

## Import Mechanism

Any workflow or batch script in VARIO Cloud can import a module using standard ES module syntax. The import path determines how the module is resolved at runtime through a virtual module system:

```javascript
// Module without a group — looked up by name
import helpers from "my_module";
```

Module resolution is virtual — there is no filesystem involved. When a script executes, the engine resolves the import path against all registered modules in the database at runtime. The file system is read-only: scripts can import modules, but cannot read or write files.

{% hint style="warning" %}
Currently only modules **without a group** can be imported. An import path containing a group (`"my_group/my_module"`) fails with "Name muss im Pfad vorhanden sein". Keep modules that other scripts import ungrouped, with the domain `LIBRARY`.

Module names and group names may only contain letters, digits, `_` and `-`. The combination of module name and group must be unique.
{% endhint %}

***

## Domains

Each module has a **domain** that indicates its intended usage context. The domain is organizational — it helps categorize modules in the UI and signals to other developers what the module is designed for.

| Domain                        | Purpose                                    |
| ----------------------------- | ------------------------------------------ |
| `LIBRARY`                     | Shared modules importable by other scripts |
| `WORKFLOW_SCRIPT`             | Workflow script tasks                      |
| `WORKFLOW_SPLIT_GATEWAY`      | Workflow split gateways                    |
| `WORKFLOW_INTERMEDIATE_EVENT` | Workflow intermediate events               |
| `IMPORT_BATCH_PROCESSING`     | Batch processing scripts                   |
| `APP`                         | App-specific modules                       |
| `UNDEFINED`                   | Not yet categorized                        |

***

## Parameters

Modules can define **typed parameters** that make them configurable. Each parameter has a `name` and a `valueType` (`string`, `boolean`, or `number`). When a module is used in a workflow or batch script, the parameter values are passed at runtime and accessible inside the script via `ctx.parameters`.

This allows a single module to serve multiple use cases — for example, one print module configured with different templates or output formats depending on the context it runs in.

***

## Presettings

VARIO Cloud ships with **preset modules** — default implementations for common tasks like printing documents, sending emails, or assigning images to articles. These presets belong to the group **Vorgabe-Stapel-Skripte** and can be used out of the box.

Users can customize a preset module by editing its script. The original version is preserved internally, and the module can be **reset to its presetting** at any time to restore the default implementation.

Unmodified presets run without a scripting licence; VARIO signs them so the system can recognise them. As soon as a preset is edited, saving and running it requires the scripting licence. Without the licence, workflows and batch actions only offer preset modules.

***

## Built-in Modules

The scripting engine provides built-in modules that are always available and cannot be modified. They are the entry points for every place where a script can run:

| Module                             | Context                                                  | Callbacks                                                           |
| ---------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------- |
| `work_item_script`                 | Workflow script tasks                                    | `setPrepare`, `setGuard`, `setAction`                               |
| `work_item_split_gateway`          | Workflow split gateways                                  | `setPrepare`, `setSplit` (returns the ID of the outgoing branch)    |
| `work_item_intermediate_event`     | Workflow intermediate events                             | `setPrepare`, `setGuard`, `setTrigger`                              |
| `batch_script`                     | Batch processing and script processing                   | `setGuard`, `setAction`, `setAfterBatch`                            |
| `output_module_script`             | Output scripts (Einstellungen → Allgemein → Ausgabe)     | `setBeforePrint` — output continues only if it returns `true`       |
| `app_scripting_proxy`              | App scripts (System → Apps → tab Skripte)                | `setProcess` — receives the app's JSON and returns the changed JSON |
| `picklist_script_pick_box_connect` | Picklist templates with consolidation or rolling picking | `setProcess` — distributes picklist lines to pick boxes             |

These are imported at the top of every script — e.g. `import workItem from "work_item_script"`. User-created modules are imported alongside them using the same syntax.

***

## Example

A reusable module that validates address fields:

```javascript
// Module: "address_validation", no group, domain LIBRARY
export default {
  validatePostcode(country, postcode)
  {
    if (country === 'DE' && (!postcode || postcode.length !== 5))
    {
      throw 'German postal codes must be exactly 5 digits.';
    }
  },

  requireField(value, fieldName)
  {
    if (!value || (typeof value === 'string' && value.trim() === ''))
    {
      throw fieldName + ' is required.';
    }
  }
};
```

Importing it in a workflow:

```javascript
import workItem from "work_item_script";
import address from "address_validation";

workItem.setAction((ctx) =>
{
  const account = ctx.availableInput.accountToSave;
  const addr = account.defaultAddress;

  address.requireField(addr.city, 'City');
  address.requireField(addr.postcode, 'Postal code');
  address.validatePostcode(addr.countryCode, addr.postcode);
});
```

{% hint style="info" %}
The same module can be imported in batch scripts, other workflow scripts, or even other modules — write once, use everywhere.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.vario-software.de/documentation/scripting/script-modules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
