You can simply run solver of another rules directly from Scripting Rule.
Last updated
#843: Audit API chages
Change request updated
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 the rule ID and solver input data. Optionally, you may specify the version of the called rule and the execution strategy.
Note that you can use rule alias instead of rule ID to identify the rule. In that case, make sure that the rule alias is unique within the space, otherwise the request will fail.
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
Return type
DR.solve() is returning the response from Solver as Array.
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
{"age": {}}
Output Model
{
"result": {}
}
Table
Decision table 2: "1111-1111-1111-1111"
Input Model
{
"total amount": {},
"blocked": {}
}
Output Model
{
"result": {}
}
Table
Scripting Rule
Script
// Get data from Inputconstdata=input.data;// Check if data is in Input and if data is an Arrayif(data &&Array.isArray(data)){constdates= [];// Iterate over data arrayfor(let dat of data){// Check if dat (member of data array) has parameter date;if(dat.date){// add date to datesdates.push(dat.date); } }// Create BULK input data for DTconstDTdata= [];for(let date of dates){constinput= {"age": date }DTdata.push(input); }// log input data for DTlog(JSON.stringify(DTdata));// Call first DT with FIRST_MATCH strategyconstDTresult=DR.solve("0000-0000-0000-0000", DTdata,1,SolverStrategy.FIRST_MATCH);// log result from DTlog(JSON.stringify(DTresult));// transform data from DT to another DTlet blocked =0;for(let res of DTresult){if(Array.isArray(res)){if(res[0].result && res[0].result =="BLOCKED"){ blocked ++; } } }// Create input data for DTconstDTdata2= {"total amount":dates.length,"blocked": blocked }// log input data for DTlog(JSON.stringify(DTdata2));// Call second DT with FIRST_MATCH strategyconstDTresult2=DR.solve("1111-1111-1111-1111", DTdata2,1,SolverStrategy.FIRST_MATCH);// log result from DTlog(JSON.stringify(DTresult2));// pass result from DT to SR resultoutput.result = DTresult2[0].result;}return output;