Search…
SDK and Frameworks
Business Intelligence
Call Embedded Rules in Scripting Rules
You can simply run solver of another rules directly from Scripting Rule.

How to call embedded rules

You can run solver of other rules from Scripting Rule.
Solver is available under class DR and method solve().
DR.solve(ruleId, data, version, SolverStrategy)
Everything that you need is ruleId and solver input data for the calling method.
If you are importing/exporting existing rules, DO NOT forget to change the ruleID you are calling in the scripting rule!

Parameters

name
type
mandatory
description
ruleId
string
Id of solving rule
data
any
Input data for solver
version
number
Version of solving rule
SolverStrategy
Solver strategy of solver

Return type

DR.solve() is returning the response from Solver as Array.

Examples

Basic method

1
DR.solve("ruleId", data);
Copied!

Method with rule version

1
DR.solve("ruleId", data, 5);
Copied!

Method with Solver Strategy

1
DR.solve("ruleId", data, 5, SolverStrategy.FIRST_MATCH);
Copied!
If you want to define Solver Execution Strategy you have to specify the rule version too.

Example of usage

The rules you want to call in the scripting rules must be in the same space.

Decision table 1: "0000-0000-0000-0000"

Input Model

1
{
2
"age": {}
3
}
Copied!

Output Model

1
{
2
"result": {}
3
}
Copied!

Table

Decision table 2: "1111-1111-1111-1111"

Input Model

1
{
2
"total amount": {},
3
"blocked": {}
4
}
Copied!

Output Model

1
{
2
"result": {}
3
}
Copied!

Table

Scripting Rule

Script

1
// Get data from Input
2
const data = input.data;
3
4
// Check if data is in Input and if data is an Array
5
if(data && Array.isArray(data)){
6
7
const dates = [];
8
9
// Iterate over data array
10
for(let dat of data){
11
// Check if dat (member of data array) has parameter date;
12
if(dat.date){
13
// add date to dates
14
dates.push(dat.date);
15
}
16
}
17
18
// Create BULK input data for DT
19
const DTdata = [];
20
21
for(let date of dates){
22
const input = {
23
"age": date
24
}
25
DTdata.push(input);
26
}
27
28
// log input data for DT
29
log(JSON.stringify(DTdata));
30
31
// Call first DT with FIRST_MATCH strategy
32
const DTresult = DR.solve("0000-0000-0000-0000", DTdata, 1, SolverStrategy.FIRST_MATCH);
33
34
// log result from DT
35
log(JSON.stringify(DTresult));
36
37
// transform data from DT to another DT
38
let blocked = 0;
39
40
for(let res of DTresult){
41
if(Array.isArray(res)){
42
if(res[0].result && res[0].result == "BLOCKED"){
43
blocked ++;
44
}
45
}
46
}
47
48
// Create input data for DT
49
const DTdata2 = {
50
"total amount": dates.length,
51
"blocked": blocked
52
}
53
54
// log input data for DT
55
log(JSON.stringify(DTdata2));
56
57
// Call second DT with FIRST_MATCH strategy
58
const DTresult2 = DR.solve("1111-1111-1111-1111", DTdata2, 1, SolverStrategy.FIRST_MATCH);
59
60
// log result from DT
61
log(JSON.stringify(DTresult2));
62
63
// pass result from DT to SR result
64
output.result = DTresult2[0].result;
65
66
}
67
68
return output;
Copied!

Input

1
{
2
"data": [
3
{
4
"date": "01/01/1990"
5
},
6
{
7
"date": "01/01/1999"
8
},
9
{
10
"date": "01/01/1930"
11
}
12
]
13
}
Copied!

Output

1
[
2
{
3
"output": "PASS"
4
}
5
]
Copied!