<div>Hello,</div>
<div> </div>
<div>I am using Drools 3.0.6. While using a global variable in a function, the compiler complains it cannot resolve the global variable name. Something like below</div>
<div> </div><b><font color="#960000" size="2">
<p>global</p></font></b><font size="2"> com.<strong>sample</strong>.ExampleLogger <strong>customLogger</strong>;</font><b><font color="#960000" size="2">
<p align="left">function</p></font></b><font size="2"> </font><b><font color="#960000" size="2">void</font></b><font size="2"> logMessage(String msg){</font><font size="2">
<p align="left"></p></font><font color="#808000" size="2">customLogger.logMessage("Log Message from the function");</font><font size="2">
<p>}</p>
<div></div></font>In the above code, it complains "customLogger cannot be resolved". I am able to refer the global in the consequence of a rule directly. What is the problem using the reference within a function.
<div> </div>
<div>On the other hand, i am able to do something like</div>
<div><strong><font color="#960000" size="2"> </font></strong>
<p align="left">function<font size="2"> </font><b><font color="#960000" size="2">void</font></b><font size="2"> logMessage(<font size="2">ExampleLogger custLogger,</font>String msg){</font></p><font size="2">
<p align="left"></p></font><font color="#808000" size="2"><font size="2">
<p>custLogger.logMessage(msg+</p></font><font color="#008000" size="2">" Accept gloabal as function parameter"</font><font size="2">);
<p align="left"></p></font></font><font size="2">}</font></div>
<div>and call from the consequence of a rule : <font size="2">logMessage(customLogger); // I am passing the global to the function as an argument and then use it to log a message. </font></div>
<div><font size="2">This way is working. But not the first way of using the global in the function. </font></div>
<div><font size="2"></font> </div>
<div><font size="2">Any help??</font></div>
<p>Thanks<br>-- <br>Natraj Gudla </p>