drools: how to assign to local variable
10,684
Solution 1
rule "test rule 1"
when
$carDao : ICarDAO( $x : map )
eval (
$x.contains("a") && $x.contains("b")
)
then
// do stuff
end
or since 5.2:
rule "test rule 1"
when
$carDao : ICarDAO( $x : map, map.contains("a"), map.contains("b") )
then
// do stuff
end
Solution 2
rule "test rule 1"
when
$carDao : ICarDAO( )
$x: java.util.Map( ) from $carDao.getMap()
eval (
$x.contains("a") && $x.contains("b")
)
then
// do stuff
end
ta..dar!
Related videos on Youtube
![mehmet](https://i.stack.imgur.com/lTWuQ.png?s=256&g=1)
Comments
-
mehmet about 2 years
I'm stuck with Drools 5 and need a little help. What I'd like to do is use a passed in DAO and assign a value from that to a local variable, like this...
rule "test rule 1" when $carDao : ICarDAO( ) $x : $carDao.getMap() eval ( $x.contains("a") && $x.contains("b") ) then // do stuff end
Drools 5 doesn't allow assignment of local variables though. I'd like to assign to a local variable so that I don't have to make the same call twice to the DAO.
So could someone point me in the correct direction please?
Thanks! Jeff Porter