Thanks Edson,
I'm aware of "accumulate" and see how it can be used to solve the specific
issue.
I'm looking for a more generic solution for updating objects.
The only reason amountFact is part of the "when" clause is for a reference
to the object that can be used by the "then" clause. It's not really part
of
the rule criteria.
If I could get a reference to it directly in the "then" clause, the update
statement would not put the rule back on the agenda - which would be
perfect.
Any ideas?
Dan
Edson Tirelli-3 wrote:
There are several ways of doing that, and some where even mentioned by
the other users. One easy way is to simply use "accumulate":
rule "update amount"
no-loop
when
$f : Fact( name == "amount" )
Number( $total : doubleValue ) from accumulate(
Charge( $amt : amount ),
sum( $amt ) )
then
modify( $f ) { setAmount( $total ) }
end
[]s
Edson
2008/11/4 Dan Seaver <dan.seaver(a)ge.com>
>
> I'm trying to find a good technique for updating specific facts in
> working
> memory. What I'm currently doing is something like this:
>
> Rule "Update Amount"
> when
> amountFact : Fact(name == "Amount")
> charge : Charge()
> then
> Double amount = amountFact.getAmount();
> Double chargeAmount = charge.getAmount();
> amountFact.setAmount(amount + chargeAmount);
> update(amountFact);
> end
>
> The update statement causes an infinite loop.
> I tried using no-loop, which works if there is 1 charge, but not if there
> are more than one.
>
> Any help with solutions or strategies would be much appreciated.
> --
> View this message in context:
>
http://www.nabble.com/Chart-notation%2C-update%2C-and-infinite-loops-tp20...
> Sent from the drools - user mailing list archive at
Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @
www.jboss.com
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context:
http://www.nabble.com/Chart-notation%2C-update%2C-and-infinite-loops-tp20...
Sent from the drools - user mailing list archive at
Nabble.com.