[rules-users] How to get value of global variable from one rule toanother

Anstis, Michael (M.) manstis1 at ford.com
Thu Jun 14 10:03:33 EDT 2007


I believe globals are to be used in the RHS of a rule and not the LHS
which uses "normal" facts.
 
I would suggest rule "AmountsAreNotNull" asserts new objects that
activate rule "CompareValue" or something similar.
 
Saving variables between rules should be accomplished using logically
asserted facts.
 
I hope this helps.
 
Mike


________________________________

	From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Alexander
Komissarov
	Sent: 14 June 2007 14:46
	To: rules-users at lists.jboss.org
	Subject: [rules-users] How to get value of global variable from
one rule toanother
	
	
	Hello,
	
	Please give me advice for best way storing global variables.
	
	global java.lang.Integer res;
	global java.lang.Integer res2;
	...
	
	I've several number of rules. One rule has variable
initialization e.g.:
	
	...
	rule "AmountsAreNotNull" salience 20
	    when
	        < conditions >
	    then
	       ...
	        res = new Integer(a.compareTo(new BigDecimal(25)));
	        res = (res == -1)?0:res; 
	        res = (res == -1)?0:res;
	        res2 = new Integer(a.compareTo(b));
	        res2 = (res2 == -1)?0:res2;
	       ...
	end
	
	The values of these variables are proper and equal 1
	
	Then next rule has comparing for res|res2 values, but they have
lost their values (res == null and res2 == null) 
	
	rule "CompareValues" salience 10
	    when
	        res:Integer(intValue == 0)
	        res2:Integer(intValue == 0)
	        result:List()
	    then
	        result.add(Boolean.TRUE);
	end 
	
	What decision you can advise me to save variables value between
rules?
	Thanks.
	____________________
	Regards,
	Komissarov Alexander
	mail: aleks.komissarov at gmail.com 
	icq: 239128267 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070614/aed51a28/attachment.html 


More information about the rules-users mailing list