Global &quot;variables&quot; aren&#39;t plain old Java variables; they are kept in a wrapped map. Functions are passed to a Java compiler &quot;as is&quot;, with only the import list added to the compilation unit.<br><br>So you can use a global in a DRL function<br>
<ul><li>by passing it as a parameter,</li><li>by accessing the global via the interface org.drools.runtime.Globals, which requires that you have the session object available so you can do kSession.getGlobals().</li></ul>The second option brings us back to square 1: you can&#39;t use a global... But a public static from any application class might be used - imports are available in functions. Which, after all, could be used for your &#39;x&#39; in the first place.<br>
<br>-W<br><br><br><br> <br><br><div class="gmail_quote">On 21 July 2011 00:13, bob.breitling <span dir="ltr">&lt;<a href="mailto:bob.breitling@rrd.com">bob.breitling@rrd.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a global defined and I am trying to use it from a function.  When my<br>
rule gets loaded into my knowledge base, I always get an error complaining<br>
about the global not being resolved.<br>
<br>
---- simplified snippet ----<br>
<br>
global int x;<br>
<br>
function void foo(int n) {<br>
    x = n;<br>
}<br>
<br>
------------------------------<br>
<br>
I get this kind of error &quot;Function Compilation error: foo (line:20) x can<br>
not resolved&quot;.<br>
<br>
Should this work?<br>
<br>
TIA,<br>
<br>
Bob<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Globals-from-functions-tp3186882p3186882.html" target="_blank">http://drools.46999.n3.nabble.com/Globals-from-functions-tp3186882p3186882.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>