Can we use multiple when then condition in a single rule in Drools.?

I am writing a .drl file to implement Drools rules. As per business requirements I need to check 3 conditions for a single rule. So my question is, is it possible to have multiple when in the same rule.

I did search for many hours, but I didn't get any useful info. Can someone please guide me how to write multiple when in the single rule in drools.

Ie is it possible to do like this?

rule "Test rule 1"
    when 
        condition1
    then
        <execute code>
    when
        condition2
    then
        <execute code>
end

Upvotes: 2

Views: 6476

Answers (3)

shail
shail

Reputation: 3

No We cannot do it. I also tried to implement the same , but eventually end up writing multiple rules to fulfil all when/then conditions, something like below

rule "RULE DESC" when CONDITION then EXECUTION end

rule "RULE DESC" when CONDITION then EXECUTION end

Upvotes: 0

Dominik Sandjaja
Dominik Sandjaja

Reputation: 6476

No, you can't. Basically, you will need to implement two rules, each one with one of the when blocks. The result should be exactly what you want.

Upvotes: 0

1737973
1737973

Reputation: 118

No, 80% sure you can not. You caught me with a opened .drl and did a try, says 'mismatched input', but fails on the inmediate token after the second then. Hence the 80% (to say some number). Cheerfully the compiler passed all along the second when without fail.

Try and post.

Upvotes: 2

Related Questions