DecisionRules Academy
  • DecisionRules Documentation
  • 🏁GETTING STARTED
    • DecisionRules Academy Introduction
    • Create an Account
  • 👥ACCOUNT
    • Log in
    • Plans
      • How to change your subscription
    • Billing Information
  • 🌌SPACES
    • What Is a Space
    • Space Dashboard
    • Users in Spaces
      • How to invite a new User
      • Roles
  • ⚖️RULES
    • What is a Rule?
    • Export & Import of the Rules
      • Export Rule
      • Import Rule
  • 📐RULE TYPES
    • Decision Tables
      • Create a Simple Decision Table
    • Decision Trees
      • Create Simple Decision Tree
    • Scripting Rules
      • Create Simple Scripting Rule
    • Workflow
      • Create a Workflow
    • Rule Flow
      • Create Simple Rule Flow
  • 🤝GET HELP
    • How to Create a Support Ticket
Powered by GitBook
On this page
  • How to create a simple decision table
  • 1. Log in
  • 2. Go to Create rule
  • 3. Create a new Scripting Rule
  • 4. Set scripting rules information
  • 5. Create an Input and Output model
  • 6. Creating rules
  • 7. Test created scripting rule
  1. RULE TYPES
  2. Scripting Rules

Create Simple Scripting Rule

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

Last updated 7 months ago

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 , you will be able to pass your credentials and log in.

2. Go to Create rule

To display the rule creation pop-up click the Create rule button on the sidebar.

3. Create a new Scripting Rule

You will be prompted to provide a name and choose between SAMPLE RULE or EMPTY RULE. For now, name the rule as you wish and choose the EMPTY RULE. The new rule will be created and its detail will be displayed. We will continue in the Rule Settings tab.

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 script. To do this, click on it's name, enter one you like and press Enter.

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".

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 Save button.

Input model

First, we delete all created objects. Then we will add our specified requirements (value1, value2) as empty objects.

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 Scripting Rule Designer 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 Save (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 Run icon at the bottom of the page. An input and output window will show up at the bottom of the page.

We can either click on the run button between input and output windows or Run 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
}

There are multiple options for user login. If you do not have an account yet, you can . After logging in to the application, the will be displayed.

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

You can find more information about input and result at .

More information about Test Bench is .

📐
create one
Dashboard
here
Solver API
login page
here