Just to add another option:
A variable to set in one and to use in another consequence can also be
a static field in some Java class, with (or without - huh!) setter and
getter.
However, no matter which technique one chooses, setting such a
variable in rule A and using its value in rule B creates two
dependencies:
- the temporal dependency that rule A must execute before rule B
- the logical dependency that an execution of rule A with some
specific set of facts must "match" the execution of rule B; in other
words, one needs to make sure that there is no confusion among
multiple executions of rule A and rule B.
Only a dynamically created object, inserted logically or not, has a
chance to handle these dependencies, with fields in addition to the
"value" to be passed on identifying the context, i.e., one or more
facts participating in the firing of A.
Anything else is playing with fire.
-W
On 05/10/2012, Davide Sottara <dsotty(a)gmail.com> wrote:
The concepts of "local" and "accessible to another
rule" are a little bit
conflicting :)
This said, as others have already pointed out, there are many ways to
achieve this result, including:
- globals
- chaining : rule A inserts a fact and "pushes" it (also) into rule B,
which
reacts to its insertion
- facts : both rule A and B see a fact in the WM and match/modify it
- queries : rule A inserts a fact and rule later B pulls it from the WM
If you could provide some more details about what you're trying to do, we
may be able to recommend the best approach. One thing for sure: the RHS of
different rules live in different scopes, so there is no way
to make a LOCAL variable (i.e. declared locally in a RHS) visible to other
rules' RHSs.
Best
Davide
--
View this message in context:
http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020156.html
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users