[rules-dev] globals

Edson Tirelli tirelli at post.com
Tue Feb 27 16:51:54 EST 2007


    Globals are application data that is made available to the engine, 
so you need to set it from outside of your rules:

workingMemory.setGlobal( "assignee", theAssignee );

   By the way you wrote your rules bellow I think you are 
misunderstanding something. If you want some help, maybe you can write 
your rules in english for us to understand what you want to do.
   The facts you will reason over, need to be asserted into the engine. 
So maybe what you need is something like:

rule "get_the_assignee"
	when
		not PhysicalPerson()		
	then
		PhysicalPerson assignee = new PhysicalPerson();
		assignee.setId(new Long(007));
                assert( assignee );
		Tools2.traceSomething(assignee.getId());
		Tools2.traceSomething("get_the_assignee");
end

rule "check_the_assignee"
	when
		assignee : PhysicalPerson()		
	then
		Tools2.traceSomething("check_the_assignee");
		Tools2.traceSomething(assignee.getId());
end


   Hope it helps.

   []s
   Edson

fanory wrote:

>Hello,
>
>My problem is to use a global variable in some rules:
>
>global PhysicalPerson assignee
>
>rule "get_the_assignee"
>	no-loop
>	salience 100
>	when
>		exists PhysicalPerson()		
>		beneficiary : PhysicalPerson()
>		eval(true)
>	then
>		assignee = new PhysicalPerson();
>		assignee.setId(new Long(007));
>		Tools2.traceSomething(assignee.getId());
>		Tools2.traceSomething("get_the_assignee");
>end
>
>rule "check_the_assignee"
>	no-loop
>	salience 50
>	when
>		exists PhysicalPerson()		
>		eval(true)
>	then
>		Tools2.traceSomething("check_the_assignee");
>		Tools2.traceSomething(assignee.getId());
>end
>
>I don't understand why when my rule "check_the_assignee" is executed, i get a
>null pointer exception on Tools2.traceSomething(assignee.getId()) ?
>The question behind this is i want to use a created object inside a rule and use
>it in others rules with lower salience ...
>
>Thanks in advance.
>
>_______________________________________________
>rules-dev mailing list
>rules-dev at lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-dev
>
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com





More information about the rules-dev mailing list