Drools: Execute a rule only after another was executed

drools rule engine
drools agenda group
drools rule execution order
drools rules in database
drools tutorial
drools workbench
drools fire specific rule
drools business central

I have two Drools rules in the same drl file like:

rule "If critical"
when 
incident:Incident(state=CRITICAL)
then
incident.getIncidentValve().activateAlarm();
end;

rule "If alarm"
when 
valve:Valve(hasAlarm==true)
then
SMS.send(valve.getId());
end;

My idea is to process, with the first rule, all the incidents that are in critical state. And then with the second rule, if any valve has an alarm, that was set by the "If critical" rule, send an SMS.

The problem is that the very first time I execute the rules the SMS are not sent. This seems to be so because the 'when' of both rules is verified at the same time.

My question is how can I tell Drools that I want to execute first the "If critical" and then, once the 'activateAlarm' methods have been called, execute the rule "If alarm" so the SMS are sent.

I have tried with salience, but that's not what I am looking for because that is only the execution order, after the validation of the 'when' is done, which as I said is done for both rules at the same time.

Also tried with agenda-group and setFocus, but it didn't take me anywhere.

Any idea? Is this possible with Drools?

The problem is that the facts after the 1st rule is executed are not updated. To use the values changed in the 1st rule you have to update the values using the update function.

Drools Documentation - JBoss Community Confluence, 1: package org.drools.examples; 2: rule 3: when 4: Object() For instance, we may want to declare another fact type Person : This tag is only considered when running the Drools "When" was chosen over "if" because "if" is normally part of a procedural execution flow, where,  Create simple rule project with rules and a ruleflow. Compile and deploy the rules to drools-server. Execute the rule engine by sending a JSON command to drools-server via cURL the first execution should work correctly. All ruleflow-group nodes should fire; the second execution with the same data should fail.

You can use salience keyword of Drools. Give positive Salience value to the first rule. See documentation here. Try defining your rule like this

rule "If critical"
salience 100 
when 
incident:Incident(state=CRITICAL)
then
incident.getIncidentValve().activateAlarm();
end;

rule "If alarm"
when 
valve:Valve(hasAlarm==true)
then
SMS.send(valve.getId());
end;.

Chapter 7. Running - JBoss Community Confluence, Drools prefers the keyword delete for symmetry with the keyword insert ; Drools The Agenda controls the execution order of these Matches using a Conflict In this group only one rule can fire, and after that rule has fired all the other rules  Let’s analyse what happens when “Apply more than 3 years seniority discount” rule is executed. The execution of this rule modifies the customer object and lets Drools to know about it. This action would generate 2 new activations: a new activation for “Apply more than 3 years seniority discount”

Use extends attribute ex- rule If alarm extends If critical

So If alarm rule will fire only after IF critical rule task completed It means creating complete dependency on previous rule And also you must have to update the fact in first rule by using modify or update if any updated value required in second rule. Hope my answer will help you.let me know if any quires on same.

Designing a decision service using DRL rules Red Hat Decision , DRL (Drools Rule Language) rules are business rules that you define directly in .​drl Each attribute has a type that can be any valid Java type, including another class This tag is available only when the decision engine is running in stream mode. engine is not continually active, but is active only after a rule is executed​. Import that project into a new Eclipse workspace. The rules all have example classes that execute the rules. If you want to try the examples in another project (or another IDE) then you will need to set up the dependencies by hand, of course. Many, but not all of the examples are documented below, enjoy!

Drools Jboss Rules 5. X Developer's Guide, The type property decides when the execution will continue. The unknown country rule used salience value of —10, which meant that it would fire only after all  How can I only allow the process to execute my business rules when the business rule node is hit? Instead of just executing the rule base at the end? Currently, regardless of where I place my business rules node my newRules.drl is executed at the end and not where I want it to.

Drools Jboss Rules 5.0 Developer's Guide, Type decides when the execution will continue. It can have The unknown country rule used salience of 10, which meant that it would fire only after all address  Hello, Using EAP 6.4 with BPM Suite 6.1. I hardly managed to deploy a couple of rules to the kie-server from business-central. But I don't find anywhere any sample of how to execute these rules, once deployed.

[PDF] Drools Expert User Guide, There are two methods of execution for a rule system: Forward Chaining and We can also add another rule to validate that the application was made within a no rule, however, is executed until you call fireAllRules(), which you call after. The call drools.halt() terminates rule execution immediately. This is required for returning control to the point whence the current session was put to work with fireUntilHalt().