Table of Contents

Scripting

The scripting feature in ERP.net provides users with a powerful tool to customize and extend core business functionality.

By enabling the creation and execution of scripts within your instance, this feature makes it possible to automate business processes, implement custom business rules, and adapt workflows to unique organizational requirements.

Scripting enhances the flexibility of ERP.net, allowing businesses to efficiently tailor their operations to specific needs.

Abstract

This documentation describes the ERP.net scripting feature, including how to create, execute, and manage scripts within your instance.

It covers supported scripting languages, integration with the domain model, available APIs, example use cases, and important security considerations.

Supported scripting languages

ERP.net supports the following scripting languages:

  • JavaScript: JavaScript is the officially supported scripting language. All new scripts should be written using standard JavaScript syntax.

  • C#: It's available as a legacy feature. Support for C# scripts will be removed in future releases and its use is not recommended for new development.

Scripting availability

Scripting is currently available only within User Business Rules.

Support for additional modules, where scripting will be available, is planned for future releases.

Script access scope

What a script can access depends on where it is executed within the system. In most cases, scripts have access to the Domain Model, allowing you to read, create, and update entities.

Additionally, scripts always have access to the Global action object- helper that provides quick access to commonly used actions.

The available objects and data may vary depending on the specific context in which the script runs.

Always refer to the documentation for your script's entry point to see exactly what is accessible in that environment.

Features

  • Full use of the scripting language syntax and all language constructs.

  • Blazing fast execution with minimal footprint.

  • Access to the current execution context (the object that triggered the script).

  • Access the entire ERP.net Domain Model from your script.

  • Global Action object for quick execution of common functions and host-specific operations.

  • Access to current session data.

  • Safe, sandboxed script execution.

Getting started

The scripting feature in ERP.net is accessible from specific modules and workflows, such as user-defined business rules within your instance.

It allows you to embed custom logic directly where business decisions or specific custom processes are required.

How to create a script

Note

The examples below are tailored for scripting within User Business Rules.

  1. Navigate to a module where scripting is supported (e.g., User Business Rules).

  2. Create a new rule or edit an existing one.

  3. In the Script Language attribute, select the desired scripting language/platform, and enter your script in the Script Text field.

Note

JavaScript is the recommended and officially supported scripting language.

  1. Complete the remaining required fields for the user business rule- such as when it should be triggered, the context repository, etc.

  2. Save.

Done.

The script will execute every time the rule is activated.

Your first script

A classic way to get started with scripting is to log a simple message. The following example demonstrates how to write "hello world" to the system log whenever the rule is triggered:

Action.log("hello world");

Once the rule containing this script is activated, you'll see "hello world" appear as a new information message.

This serves as a simple test to confirm that your scripting environment is working correctly.

Note

The Action variable is a reference to the global action object. You can find more information and usage details here.

Next steps