Multiple Actions in a single rule

47 views
Skip to first unread message

Aditya Mishra

unread,
Apr 8, 2024, 1:42:51 AMApr 8
to Drools Usage
Hi,

I'd like to know if there's a way to add multiple actions inside a single rule based on conditions or so, similar to an if-else-if statement or a switch case (I know Drools rules return boolean values but I am looking for non boolean return types for my use case as I have multiple rules and if-else structure suits it well)
Something like this :
Rule 1
   if condition A
   action A
   if condition B
   action B
....
I also wish to know if there's a way to call another rule from one rule. Any sample rule helps.

Richard Bourner

unread,
Apr 8, 2024, 12:16:10 PMApr 8
to Drools Usage
What you are trying to achieve should actually be 2 separate rules, 1 for A and 1 for B.

You cannot call a rule from another rule, that defeats the purpose of an inference engine. But what you can do is set some flag in the action part of rule 1 that will make conditions of rule 2 to satisfy and therefore forces the 2nd one to fire after the 1st. That flag could be a new object to be inserted, or an attribute of an existing object.

Jared Davis

unread,
Apr 11, 2024, 10:46:04 AMApr 11
to Drools Usage
The 8.44 doc is missing a section in error related to this topic. I was assured this was a supported operation.

On Monday, April 8, 2024 at 1:42:51 AM UTC-4 Aditya Mishra wrote:

Daniel Clark

unread,
Apr 12, 2024, 2:28:25 AMApr 12
to drools...@googlegroups.com
You could also look at named consequences, although it is often simpler just to use two distinct rules.
https://blog.kie.org/2012/09/conditional-named-consequences-in-drools-5-5.html

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/099e8007-a95a-4576-938a-c95162e62316n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages