Scripting Rule Introduction
Last updated
Last updated
Scripting Rule is another type of rule that you can use in DecisionRules to create your rules and conditions. However, it differs fundamentally from the others in that it does not have a graphical editor, it uses the Monaco code editor instead.
Just like the other rules, it has a unified Rule Settings form that is the same across all rule types.
So when you are creating a rule, the procedure is exactly the same, first, you create an input and output structure in Rule Settings. You can also create your own Rule Variables.
Next, you move to the Scripting Rule Designer and create the rule and all the logic using JavaScript.
The Scripting Rule Designer uses the standard and well-known Monaco editor from VS Code to help the user with code creation and editing. Of course, it also includes all the Functions and Operators that are available in Decision Table or Decision Tree.
Below you can find example file with Scripting Rule. This rule contains a function that return random number from given range.
What is important to note is that you should always have “return output;” in the last line of your Scripting rule.
Although DecisionRules is a No-code & Low-code solution, in some cases it is useful to take advantage of the flexibility that using the code offers. In particular the ability to create your own function or copy it from already created code. Using Scripting Rule is mainly meant for Developers, Analysts or anyone who is capable and willing to use JavaScript.
One of the most popular use cases is when a developer creates a generic script that processes data. This script then changes very little, because all the parameterization of that script happens in the Decision Table or Decision Tree, where it is already being modified by people from the business or product teams.
Although Rule Flow was primarily intended for rule orchestration, with using Scripting Rule for rule orchestration, it is possible to enrich such orchestration with custom and more advanced features. An example of orchestration using Scripting Rule is the use of the DR.solve function, which calls the required rules from code and can further manipulate the data that such rules return as output.
The Scripting Rule, like other rules in DecisionRules, has its own versioning and change history. But what you can do more in the case of Scripting Rule is to use GitHub. Thanks to the Management API, you can connect your GitHub to DecisionRules and use GitHub to manage code edits, versioning and merging of unique versions.
Whenever you make a change to a rule, save it with the Save button.
Thanks to Scripting Rules, DecisionRules can have the Best of Both Worlds.
The sheer flexibility offered by the code and the user-friendly interface of Decision Table or Decision Tree that can easily be used by a non-technical person. The key is to use the solve function. Where Scripting Rule takes care of advanced data manipulation and uses the solve function to parameterize the Decision Table or Scripting Rule.
Scripting Rule allows you to create custom functions, make advanced data manipulation, aggregations, iterations. You can also very easily copy functions and code that you have already created in JavaScript.
In the following sections you can find more details about Scripting rule features.