Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Rule name in "then" clause in drools

Tags:

drools

Is it possible to retrieve rule name in the then clause of drool rule?

rule "A"
    when
        ---
    then
        // something that outputs "A"

Thanks.

like image 950
Manish Mulani Avatar asked May 29 '12 08:05

Manish Mulani


People also ask

How do you call one rule from another rule in Drools?

Well, the answer is we can't call a Rule from another Rule. Drools matches the Rules with incoming data/facts, and if the data satisfies the Rule condition, it stores the data in an Agenda. It might be possible for the same data or facts to be matched by different rules, so it stores matching facts in an Agenda.

How do you define a rule in Drools?

Rule Definition − It consists of the Rule Name, the condition, and the Consequence. Drools keywords are rule, when, then, and end. In the above example, the rule names are “Hello World” and “GoodBye”. The when part is the condition in both the rules and the then part is the consequence.

How do I iterate list in Drools?

List list = dpojo. getAnswers(); for( Object obj: list ){ String s = (String)obj; if( s. length() > 0 ){ ... } }

What is DRL file in Drools?

DRL (Drools Rule Language) rules are business rules that you define directly in . drl text files. These DRL files are the source in which all other rule assets in Business Central are ultimately rendered.


2 Answers

Yes, in then clause you may use expression:

drools.getRule().getName()
like image 163
Cyril Sochor Avatar answered Oct 05 '22 08:10

Cyril Sochor


As Cyril said, you can get the rule name in the then clause by calling drools.getRule().getName() of the drools rule.

Just a little more info, you can check the getName() method in Rule Interface in the following api: http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/definition/rule/Rule.html

like image 34
Shekh Akther Avatar answered Oct 05 '22 08:10

Shekh Akther