We have a scenario to be implemented in Decision Table to exit from executing the remaining rules if certain rule successfully executes the action part of the rule. Suppose I have 50 rules and 5th rule is something which says insurance claim is invalid then we set claim as invalid to the object, then there is no need to execute remaining rules. How could this can be achieved. Please suggest
You can
retract the fact under evaluation, after setting invalid to true, on that rule's RHS,
throw an exception (ugly, ugly),
run the session using fireUntilHalt and call method halt on the session on that rule's RHS - here you'll need a very low salience rule (added in a .drl file) to call halt in case the fact passes all decision table rules.
Related
With drools, is there a way to tell which part of a rule's "when" clause has failed that prevented the rule from firing? Or, barring that, to tell whether a rule did not fire because its conditions were not satisfied, or if it simply had a lower salience than a rule that halted the context?
I am using drools in my project and assume it has 100 rules. I have two process flow (typically it has start node->rule flow task->end node). One process flow's rule flow task is specified with rule flow-group which is assigned to 50 rules and another process flow's rule flow task is specified with flow flow groups which is assigned to rest of the 50 rules. The don't overlap.
Now I use kiesession and call start process of first process flow, I see that it loads all the 100 rules instead of only 50 and gives me compilation and runtime errors. So please help me in understanding why rules from different rule flow groups are getting executed in a process flow where those rules are no where related its rule flow-group ? I see all its when conditions are getting loaded.
The "unit of work" in Drools is the KieBase and not the rule-flow-group. All the rules in your KieBase will be present in your KieSessions and will be evaluated when required.
Hope it helps,
For reusable perspective, I have one Rule with Rule Flow group. I have use same rule flow group multiple times in flow. Now the situation is its should be fire same rule more then one time,but its only fire that rule single time.
I don't understand why its happens.
Can you give me an idea why its happening and whats the solution for same?
A Rule Task in a flow does not "execute" the rules in a rule-flow-group, it merely activates that group in the agenda so IF there are active rules, they will fire.
If between 2 executions of your Rule Task you modify the session in a way that new activations are created, consecutive executions of your task should fire new activations of those rules.
Hope it helps,
I have created a process in jbpm 6. There is a class Person, with attributes name and age. In the process form, the name and age of the person is entered. The first node in the process is a human task to view the details. The second node is an XOR gateway with drools expression on its arcs like Person(age > 20) and Person (age < 20).
Now when I execute the process instance, the first human tasks works fine, but when it reaches the gateway, I can see this error -
"XOR split could not find at least one valid outgoing connection for
split Gateway".
Any idea whats wrong.
Gateways containing drools expressions only work with facts and not with process variables. If you want to make use of a drools expression in your gateways, you will need to insert the process variable (or the whole process instance) as a fact. You can do so by using a script node, an outgoing action in your human task.
From documentation:
Rule constraints do not have direct access to variables defined inside the process. It is however possible to refer to the current process instance inside a rule constraint, by adding the process instance to the Working Memory and matching for the process instance in your rule constraint. ....... Note that you are however responsible yourself to insert the process instance into the session and, possibly, to update it, for example, using Java code or an on-entry or on-exit or explicit action in your process.
Hope it helps,
I defined multiples rules in one DRL file, how to set order, want to execute one after another (top to bottom).
Rules are fired automatically when the conditions are met when the inserted facts(objects) are updated. But if in case you want to run it from top to bottom, you can set a property called salience in the rule. The value it takes is an integer. The rule with the highest salience is executed first.
rule "First name mandatory"
salience 10
when
(Person(firstName=="" || firstName==null))
then
...
end
If you use salience you will be killing the rule engine, because you will be forcing the rule execution order instead of letting the engine decide.
Cheers
Setting priority to rules is the best form.
Use Salience to determine the priority of each rule, where a higher number denotes a higher priority.
The default Salience for rules is 0, and you can give negative Salience, for example,if you want a rule to be fired last.