[rules-users] How to use global variables

goforcrazy goforcrazy at gmail.com
Mon Mar 18 20:44:21 EDT 2013


Hi All,

My rule file is as shown below:

global Integer count;

rule "Rule1"

when   eval(1==1)
then
       for(int a = 0; a<10; a++)
 		{ 
 			System.out.println("1 COUNT: " + count);
 			count++; 			 
		}

rule "Rule 2"
when   eval(1==1)
then
       for(int a = 0; a<10; a++)
 		{ 
 			System.out.println("2 COUNT: " + count);
 			count++; 			 
		}


As shown above I have created a global variable count in my drools file. In
my Java file I have included ksession.setGlobal("count", 1); to start the
count from 1 for first rule but after Rule 1 gets executed and before the
beginning of rule 2 I find that count value is again taken as 1. It does not
remember the last count value at the end of the loop. 

I understand I need to use the workingMemory function to update the result
of count but I am not sure on how and where to update the same.

Any help regarding this will be greatly appreciated.

Thanks and Regards,
Malathi




--
View this message in context: http://drools.46999.n3.nabble.com/How-to-use-global-variables-tp4022860.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list