All accesses to a global must be done via setGlobal/getGlobal:<br>  drools.getWorkingMemory().setGlobal( &quot;prodCat&quot;, getName(nameList) );<br><br>It&#39;s not a Java variable.<br><br>-W<br><br><div class="gmail_quote">
On 4 November 2010 20:59, rajivharris <span dir="ltr">&lt;<a href="mailto:rajivharris@gmail.com">rajivharris@gmail.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;">
<br>
Hi ,<br>
<br>
Thanks Bruno and Wolfgang for replying.<br>
<br>
The getname() is a drools function which i want to invoke at runtime and set<br>
the global variable.<br>
Code:<br>
global String prodCat;<br>
<br>
rule &quot;Your First Rule&quot;<br>
<br>
        when<br>
                #conditions<br>
                nameList : ArrayList()<br>
                //prodCat : String()<br>
                eval (nameList.size() &gt; 0)<br>
        then<br>
                #actions<br>
                prodCat = getName(nameList);<br>
                //modify (prodCat);<br>
                System.out.println( &quot;ArrayListSize:&quot; +nameList.size());<br>
                System.out.println( &quot;ProductCategory:&quot; +prodCat);<br>
<br>
end<br>
<br>
function String getName(List lstName)<br>
{<br>
        String name= &quot;&quot;;<br>
        String prodCat = &quot;&quot;;<br>
<br>
        for (Iterator iterator = lstName.iterator();iterator.hasNext();) {<br>
                Map dsName= (HashMap)iterator.next();<br>
                prodCat = dsName.get(&quot;name&quot;).toString();<br>
<br>
                if(prodCat.equalsIgnoreCase(&quot;Rajiv&quot;))<br>
                {<br>
                        name= &quot;Rajiv&quot;;<br>
                        break;<br>
                }<br>
                else if(prodCat.equalsIgnoreCase(&quot;Robin&quot;))<br>
                {<br>
                        name= &quot;Robin&quot;;<br>
                }<br>
        }<br>
        return name;<br>
}<br>
<br>
JAVA:<br>
String prodCat = &quot;dummy&quot;;<br>
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br>
ksession.insert(lstName);<br>
ksession.setGlobal(&quot;prodCat&quot;, prodCat);<br>
ksession.fireAllRules();<br>
System.out.println(&quot;Output:&quot;+ksession.getGlobal(&quot;prodCat&quot;));<br>
<br>
--Rajiv<br>
<font color="#888888">--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/accessing-a-drools-variable-tp1843203p1844248.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/accessing-a-drools-variable-tp1843203p1844248.html</a><br>

Sent from the Drools - User 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>