You can define global variables inside a rule. This variable can be populated through Java as follows:
public void init() {
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
String string = "foo";
ksession.setGlobal("var", string);
}
In a rule, this global access can be accessed through the global keyword:
global String var;
rule "Test"
when
then
end
source
share