Create Simple Scripting Rule

This tutorial will walk you through the creation of a simple Scripting Rule.

How to create a simple decision table

Let's advance one step at a time.

1. Log in

Becoming a superhero is a fairly straightforward process. After entering our login pagearrow-up-right, you will be able to pass your credentials and log in.

There are multiple options for user login. If you do not have an account yet, you can create onearrow-up-right. After logging in to the application, the folder structure of your Rules List will be displayed.

2. Create a new Scripting Rule

To display the rules creation list, click the + Create button on the search bar. Select your rule and you will be prompted to provide a name. For this example, select a name for your rule as you wish and press "Confirm". The new rule will be created and its design interface will be displayed. We will continue in the Rule Setting menu.

3. Make basic settings

Rule Settings will be in a left-hand side menu, or you can access them by Rule Model at the top bar. Let's do some settings. Since we do not want this decision table to be available yet, we will change its status to Pending. To do this, switch on the current status Published to Pending.

To apply these changes, we have to click the Save button at the top of the page, right corner.

4. Create an Input and Output model

We will now create an input and output model, which we will then use to set conditions and results. We create this model with a JSON editor.

circle-info

After creating an input or output model, we must always confirm the changes with the Save button.

Input model

First, we delete all created objects. Then we will add our specified requirements (value1, value2) as empty objects. Let's start with the input model. First, you can switch from "Designer" to "Model" at the centre of the top bar. Change from Simple Editor to JSON Editor at the toggle next to the "Rule Settings" button. Delete all default objects. Then add your specified requirements, e.g. value1, value2, as empty objects.

circle-info

Because our model is simple, these objects do not contain any others. For more complex models, more information is herearrow-up-right.

Input model Example:

Output model

We set the output model similarly, where we set it as root result (empty object).

Output model Example:

6. Creating rules

Now let's move on to code editor by clicking on Scripting Rule Designer it in the upper center and create individual rules.

circle-check
circle-check

For simplicity, we will remove the code from the code editor to create a new rule.

When to code editor is empty, we can start to create our own rule in JavaScript. It is straightforward, and you need to write your code which can look like below.

circle-check
circle-info

console.log() is forbidden due to performance, but you can use log() instead.

circle-check
circle-info

Always save your script using Save (bottom of the page) or CTRL/CMD + S

7. Test created scripting rule

circle-exclamation

Now we can test our rule. Before testing the rule, we must change the status of the rule to "Published".

If we want to test a rule, we can click on the Test Bench button. An input and output window will show up at the bottom of the page. Press the Run icon at the center of the window.

circle-check

The result will be displayed in the Output window (the right one).

circle-info

The debug mode can be turned on by clicking on Debug off . In scripting rules, it will enable to write log() in the console.

Request body example:

Response body example:

circle-info

More information about Test Bench is here.

Last updated