[rules-users] modify and update is not working in the rule file
Wolfgang Laun
wolfgang.laun at gmail.com
Fri Aug 17 09:10:47 EDT 2012
Although you can write
rule r
when ...
then
boolean b = true; ... x ....
end
there is no way you can access these variables from anywhere else but
the place marked with "x", i.e., inside the very same rule.
To see whether certain rules have fired in a certain interval, you'll
have to use some global data, either a DRL global or some other public
instance. At the beginning of the interval you'll have to clear the
variable, and at the end of the interval you'll have to iterate over
the accumulated collection.
For instance:
Java code:
Set<String> ruleNameSet = new HashSet<String>();
kSession.setGlobal( "ruleNameSet", ruleNameSet );
//...
// Loop inserting a fact and firing all rules
for(...){
ruleNameSet.clear();
kSession.insert( anotherFact );
kSession.fireAllRules();
for( String ruleName: ruleNameSet ){
//... ruleName has fired
}
}
DRL code:
global Set ruleNameSet;
rule xyz
when...then...
ruleNameSet.add( drools.getRule().getName() );
end
Alternatively, to avoid the global and the addition to all right hand
sides, you can set up a listener and modify the Set<String>
ruleNameSet accordingly.
-W
On 17/08/2012, Rana <ven12344 at yahoo.com> wrote:
> How to use boolean variables in the rule. I want to do this
>
> rule
> when
> //condition
> then
> set a boolean to true
> end
>
>
> Then check at the last rule if all the boolean in the rules are true, which
> tells me that all the rules have passed.
>
> Thanks.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/modify-and-update-is-not-working-in-the-rule-file-tp4019158p4019240.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list