Create Simple Scripting Rule

1. Sign in

Becoming a superhero is a fairly straight forward process:
After entering the page, the login screen will be displayed.
There are two options for user login. Sign in with:
  • email and password
  • Google Account (SSO)
After logging in to the application, it will display the Dashboard.

2. Go to Scripting Rules

To go to the Decision Table page on the left in the sidebar, click on the Scripting Rules link. After clicking on the link, a page with all already created scripting rules will be displayed.

3. Create a new Scripting Rule

To create a new rule, click the button
. After clicking, a new scripting rule will be created, and its detail will be displayed automatically with the sample scripting rule.

4. Set scripting rules information

When you click on RULE SETTINGS on the top left corner, the scripting rule's detail will appear first to set some information. We will change the name of our decision table. To do this, click on his name. Then a field will appear where we can rename the name and click on the
icon. To cancel the changes, click on the
Since we do not want this decision table to be available yet, we will change its status to "Pending". To do this, click on the current status "Published" and then select "Pending".
For applying these changes, we have to click on the
button on the left.

5. 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.
After creating an input or output model, we must always confirm the changes with the

Input model

First, we delete all created objects. Then we will add our specified requirements (value1, value2) as empty objects.
Because our model is simple, these objects do not contain any others. For more complex models, more information is here.

Input model Example:

"value1": {},
"value2": {}

Output model

We set the output model similarly, where we set it as root result (empty object).
Output model Example:
"result": {}

6. Creating rules

Now let's move on to code editor by clicking on
it in the right upper corner and create individual rules.
Our code editor is based on Monaco Editor, using its features, like autocomplete, syntax highlight, line numbers, etc.
Shortcut Keys are also working, but you need to be with a cursor in the editor.
CTRL/CMD + S - save
CTRL/CMD + R - run
CTRL/CMD + Z - undo
CTRL/CMD + SHIFT + Z - redo
CTRL/CMD + F - find
SHIFT + ALT + F - format
Scripts must be written in JavaScript language.
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.
Input must always be entered as input.yourInputVariable.
Output must always be entered as output.yourOutputVariable.
To return an output, always enter return output at the end of your script!
console.log() is forbidden due to performance, but you can use log() instead.
You can use log() to print values in the console, which is at the bottom of the code editor.
1. Input variables
Input body is set in input variable
let a = input.value1;
let b = input.value2;
2. Define simple "multiply" function
function multiply(a, b) {
return a * b;
3. Execute multiply function and store value result variable
let resultMultiply = multiply(a, b);
4. Set output model which is returned in REST API
output.result = resultMultiply;
Optionally: It is possible print values to console
log('Result multiply:', resultMultiply);
5. Return output
return output;
Always save your script using
(bottom of the page) or CTRL/CMD + S

7. Test created scripting rule

Don't forget to save your scripting rule!
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
icon at the bottom of the page. An input and output window will show up at the bottom of the page.
You can find more information about input and result at Solver API.
We can either click on the run button between input and output windows or
the button on the top of the code editor. The result will be displayed in the Output window (the right one).
The debug mode can be turned on by clicking on
. In scripting rules, it will enable to write log() in the console.

Request body example:

"value1": 2,
"value2": 4

Response body example:

"result": 8
More information about Test Bench is here.