Say Hello to Scripting in ERP.net (v.26)

We've got some exciting news for all ERP.net users: scripting is here!

Scripting in ERP.net is a powerful addition to the set of tools you already have, making it easier than ever to tailor your system to fit your unique processes.

Now, you can write scripts directly in ERP.net, bringing a whole new level of customization and automation to your business logic.

How does it work?

Anywhere scripting is supported, you'll see new fields- just pick "JavaScript" as your script language, enter your code, and you're ready to go.

You get access to your entire domain model, so reading, creating, or updating data is just a few lines away.

There's also a handy global Action object, which lets you log information, send notifications, or even call external APIs right from your script.

And don't worry- scripts run in a safe, sandboxed environment, so your data and system performance remain protected.

For now, scripting is available only in user business rules. More areas of ERP.net will support scripting in future updates.

A few things you can do (already)

The real beauty? You can express your business logic freely, using the full power of the JavaScript language. No more rigid templates or workarounds- just write the rules you need, as you'd naturally think of them.

  • Full access to the domain model: Work with any entity or related collection- create new records, update data as needed.

  • Real-time automation: Perform complex validations with ease and send notifications to the right users at exactly the right moment- all driven by your business processes.

  • Integration with external services: Call APIs or connect to outside platforms directly from your scripts.

Why is this a big deal?

Before scripting, many custom requirements meant long workarounds or complex calculated attributes.

The current user business rules engine in ERP.net is already powerful, but sometimes it falls short when it comes to expressing more dynamic or procedural logic. E.g., simple tasks like creating a new related entity or performing multi-step updates can be surprisingly tricky- or even impossible without scripting.

Now, these previously "out-of-reach" tasks are as easy as writing a few lines of code.

For example:

Suppose you want to ensure that only whole numbers are allowed for quantities in sales order lines.
Previously, you'd have to create a separate calculated attribute just for this validation:

Before:

  • Repository: Crm.Sales.SalesOrderLines

  • Event: COMMIT

  • Action: FAIL (show message if condition fails)

  • Condition: Custom calculated attribute checks if the quantity is a whole number

Now, the same check is a simple script, right inside your rule:

// Cancel the operation if the quantity is not a whole number
if (subject.Quantity != null && subject.Quantity.Value % 1 !== 0) {
   Action.cancel("You have entered a decimal number as a quantity. Please check the data entered in the sales order lines and try again!");
}

No extra attributes, no workarounds- just clear and effective logic where you need it.

--

But the real breakthrough? Scripting opens up tasks that were simply impossible before.

How about if you want to automatically add default lines on document creation?

Previously, this kind of automation wasn't possible with traditional business rules. Now, it's as simple as hooking into the CREATENEW event and adding your logic:

// On the CREATENEW event for SalesOrders
if (subject.Lines != null && subject.Lines.Count == 0) {
   var defaultProduct = Domain.General.Products.ProductsRepository.getById("YOUR-PRODUCT-ID-HERE");
   if (defaultProduct) {   
       var line = Domain.Crm.Sales.SalesOrderLinesRepository.createNew();
       line.SalesOrder = subject;
       line.Product = defaultProduct;
       line.Quantity = new Domain.Types.Quantity(1, defaultProduct.BaseUnit);
   }
}

Or maybe you need to validate a customer's VAT number live against the official VIES database during an order process?

No problem- now you can easily call external services right from your business rule.

See an example VAT VIES check script here.

--

And this is just the beginning- support for scripting will keep expanding across the platform.

Get started

Curious to see what scripting can do for you? Check out these resources:

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk