You can't call one rule from another as rule evaluation isn't procedural, when
working with rules you are declaring what should happen in different circumstances and
it's up to the rules engine to decide how to evaluate it. One very important thing to
remember is that rule evaluation happens in two phases, first all the then parts of the
rules are evaluated and matching rules placed on a priority activation stack; only then
are the conditions evaluated. This means in the example you give below rule2 will always
be evaluated and could generate a null pointer exception even if the action of rule1 were
to terminate the rules execution.
That said there are (at least) three ways you can get the general result you want:
1. Just have a single rule which does both parts of your actions - is there any reason why
you want to keep them separate?
2. As you have said just duplicate the conditions, depending on how you are generating
your rules this may not be a big issue.
3. Use a customer helper object "ConditionMatched(conditionName)", have the rule
with the conditions use insertLogical to insert a new ConditionMatched object with the
desired name. Other rules can then match against the existence of the ConditionMatched
object rather than duplicating all the logic. InsertLogical has the nice property that if
the rule which triggered it becomes false then the object is automatically retracted
again.
Thomas
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-
bounces(a)lists.jboss.org] On Behalf Of Dinesh kumar
Sent: 02 June 2010 02:30
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Calling a rule within a rule
Hi All,
I am new to Drools and I need a help.
Is it possible to call a rule within a rule.
i.e., only when rule1 condition is true , my rule2 should execute
rule1
when a!=null
then
...
rule2
when a.toString() !=""
then
...
Though i can write both the conditions in the same rule, its not a feasible
solution as my business rules are much complicated. I am expecting to write
something like this..
rule1
when a!=null
then
when a.toString() !=""
then
...
end
end
But this is not working out. It would be great if someone can help me out..
Also I understood that variables cannot be declared in guvnor.. Is this
true..? If true then what is an alternative. Kindly help me
Regards,
Dinesh
--
View this message in context:
http://drools-java-rules-
engine.46999.n3.nabble.com/Calling-a-rule-within-a-rule-tp863409p863409.html
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************