Try reading the Drools Expert User Guide section about the use of Globals :)

Globals are not Facts to be reason in the Left-Hand-Side (WHEN) part of a rule.

Either use the Global (assuming it contains static data) and initialize it correctly from within Java code (see the User Guide) or insert it as a Fact and reason with it.

With kind regards,

Mike

On 26 July 2012 09:38, zeeshan <zeeshan.spring@gmail.com> wrote:
Hi All !

I am trying use global variable in DRL file but when I am using it, gives
Exception. Please have a look at the DRL file -----




package com.drools.rules
import com.drools.facts.*;
*global CSVBeanAgent csvAgent;*  [here I have declared the Global variable]



rule "Calculating Agent APE"

        salience 35
        no-loop true
        when

                $csvPolicy : CSVBeanPolicy()
                //$csvAgent : CSVBeanAgent()
        then


   System.out.println("For agent --->zzzzz in rule setting premium form
rate>>>>"+$csvPolicy.getPremiumMode());
    double policyAPE=$csvPolicy.getPolicyAPE();
    System.out.println("policyAPE>>>>>"+policyAPE);
    *System.out.println("Agent
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz>>>>>"+csvAgent);*
    double agentAPE=0.0;
      if(csvAgent.getAgentNo()==$csvPolicy.getAgentNo()){
      System.out.println("inside if");
     agentAPE=agentAPE+policyAPE;
      }
      csvAgent.setAgentAPE(agentAPE);
           System.out.println("AgentAPE>>>>>>>>>>>>>>>"+csvAgent.getAgentAPE());
           update($csvPolicy);

end


Above is my rule....the Bold one is I am trying to the value of *csvAgent*,
it gives *null* value. Please help me in finding the solution i.e. How to
declare the global variable and how to use it in DRL file.

Thanks !






--
View this message in context: http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users