I have a rule that fires many times for products that match my product code. How do I get all the products that have been matched? I know I can use a global and a set, but is there another way?
global Set set
rule "match multiple products"
when $prod: Product(code=='PRD-MERCH') from productList
then
System.out.println('Matched Products');
set.add($prod);
end
First of all, let me tell you that the from productList
you are using already looks suspicious. Is productList
a global?
Now, going back to your question, if you are interested in all the Product
facts that match, you can use a collect
pattern:
rule "match multiple products"
when
$prods: List(size > 0) from collect (
Product(code=='PRD-MERCH') from productList
)
then
System.out.println("Matched Products"+ $prods);
end
Hope it helps,
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments