I have a requirement to get rule name in my custom function where I use it for some processing , Below code is how I'm trying to do. If this is not possible directly, is there an alternative . BTW currently we are using Drools 5.6
import org.drools.spi.KnowledgeHelper;
function boolean printRuleName(KnowledgeHelper context ) {
System.out.println(context.getRule().getName());
return true;
}
// rule values at C15, header at C10
rule "MY_RULE_15"
salience 65521
when
k:StatefulKnowledgeSession(true == "true")
//context: KnowledgeHelper(true=="true")
m:Map(true == "true")
Map((printRuleName(kcontext) == "true")
then
System.out.println(kcontext.getRule().getName());
//this works in action
end
//Map((printRuleName(kcontext) == "true") this is causing null pointer exception, kcontext is not getting injected