The latter approach is particularly powerful we have a very simple but
amazingly flexible class called Affirmation which just have 3 fields - String
name, Object subject, Object value. This however gives most flexibility that
you need
Eg
rule Hungry
when
$person : Person(hoursSinceLunch2 || donutsOnDesk==0 ||
candybarsInDrawer==0)
not Affirmation(name == PersonIsHungry, subject == $person)
then
insert(new Affirmation(PersonIsHungry, $person, true);
end
rule Food
when
$person : Person()
Affirmation(name == PersonIsHungry, subject == $person, value == true)
not Affirmation(name == PersonHasLookedForFood, subject == $person)
then
modify($person) {
lookForFood()
}
insert(new Affirmation(PersonHasLookedForFood, $person));
end
- I;ve also updated the rules so they are less likely to retrigger multiple
times if some other rules modify person
Thomas
-Original Message-
From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
boun...@lists.jboss.org] On Behalf Of mjohansen
Sent: 21 July 2011 22:18
To: rules-users@lists.jboss.org
Subject: Re: [rules-users] How to reuse a result of a rule in an other rule
Basically, you can either update an object with the results of the first
rule, or
create a new object.
Like:
rule Hungry
when
$person : Person(hoursSinceLunch2 || donutsOnDesk==0 ||
candybarsInDrawer==0)
then
$person.setHungry(true);
update($person);
end
rule Food
when
$person : Person(hungry==true)
then
$person.lookForFood()
end
or
rule Hungry
when
$person : Person(hoursSinceLunch2 || donutsOnDesk==0 ||
candybarsInDrawer==0)
then
$hungry=new Hungry();
$hungry.setPerson($person);
insert($hungry);
end
rule Food
when
$person : Person()
$hungry : Hungry(person==$person)
then
$person.lookForFood()
end
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-
reuse-a-result-of-a-rule-in-an-other-rule-tp3182344p3189730.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
**
This message is confidential and intended only for the addressee. If you have
received this message in error, please immediately notify the
postmas...@nds.com and delete it from your system as well as any copies. The
content of e-mails as well as traffic data may be monitored by NDS for
employment and security purposes. To protect the environment please do not
print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX,
United Kingdom. A company registered in England and Wales. Registered no.
3080780. VAT no. GB 603 8808 40-00
**
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users