Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global variable in Drools rule

Tags:

java

drools

jbpm

Is there any way I can get back the Integer value updated in Drools rule. I am passing the string in my rule. I can see my rule running but I am not getting the updated global variable's value. Here is my Drools rule file :

import com.MessageType;

global java.lang.Integer delayInSeconds;

rule "Delay for Update"
when 
String(this == MessageType.UPDATE.getType())
then
System.out.println("Running delay rule.....");
delayInSeconds = 10;
update(delayInSeconds); // This gives me runtime error. If I remove it I dont get error but dont get updated value.
end

I have also tried this : kcontext.getKieRuntime().setGlobal("delayInSeconds" , 10); but no luck :(

I know I can pass this variable by setting in POJO. So just wanted to confirm if there is any way by we can get updated value using global Integer. Please suggest.

like image 494
rishi Avatar asked Dec 01 '16 12:12

rishi


1 Answers

For me this worked

drools.getKnowledgeRuntime().setGlobal(String, Object);

Eg.

drools.getKnowledgeRuntime().setGlobal("delayInSeconds", Integer.valueOf(10));

like image 124
Shivansh Gaur Avatar answered Sep 24 '22 06:09

Shivansh Gaur