I have business rules implemented in Drools, while executing I get java RuntimeException
Unexpected global [myService]
org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:588)
What could be the cause?
Rule:
rule "Tax Rule"
when
calculateTax : calculateTax(
objOne : objOne,
objTwo : objTwo,
objThree : objThree
);
objFour : objFour();
System.out.println("debug");
then
...
end
To declare and set a global in your DRL, you need to declare it and initialize it:
// DRL file
global Service myService
// Java application
StatefulKnowledgeSession session = ...
session.setGlobal("myService", new Service() );
Failure to declare the global in the DRL file or a mismatch of the global's name and the first argument in the setGlobal call result in the error message as posted.