<HTML><BODY>
Hello, for the first time I have the need to define a global variables in a DRL file, and from what it seems from the documentation it shall be a variable visible to all my rules in the &nbsp;DRL file.<div>However I don't see what I do wrong, but the modifications made by one rule are not visible to the others.</div><div>Here is illustration of what I have:<br><br>[Fact model code]<br><div>public class TestPOJO {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private int fieldOne;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private String fieldTwo;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public int getFieldOne() {...}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public void setFieldOne(int fieldOne) {...}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public String getFieldTwo() {...}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public void setFieldTwo(String fieldTwo) {...}</div><div>}</div></div><div><br></div><div>[DRL rule code]<br><div>global java.lang.Double myGlobal;</div><div>rule "Your First Rule"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>salience 2</div><div>&nbsp; &nbsp; when</div><div>&nbsp; &nbsp; &nbsp; &nbsp; TestPOJO(fieldOne &gt; 10)</div><div>&nbsp; &nbsp; then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This is rule #1");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(myGlobal);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; myGlobal = 0.03;</div><div>end</div><div>rule "Your Second Rule"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>salience 1</div><div>&nbsp; &nbsp; when</div><div>&nbsp; &nbsp; &nbsp; &nbsp; TestPOJO(fieldTwo == "true")</div><div>&nbsp; &nbsp; then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("This is rule #2");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(myGlobal);</div><div>end</div></div><div><br></div><div>[Call to Drools]<br><div>TestPOJO myTestFact = new TestPOJO();</div><div>myTestFact.setFieldOne(15);</div><div>myTestFact.setFieldTwo("true");</div></div><div><br></div><div><div>KieServices ks = KieServices.Factory.get();</div><div>KieContainer kContainer = ks.getKieClasspathContainer();</div><div>KieSession kSession = kContainer.newKieSession("ksession-rules");</div><div>&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span></div><div>kSession.insert(myTestFact);</div><div>kSession.fireAllRules();</div></div><div>kSession.dispose();</div><div><br></div><div>[Output]<br><div>This is rule #1</div><div>null</div><div>This is rule #2</div><div>null<br><br><br>[What I expect to have as output]</div></div><div><div>This is rule #1</div><div>null</div><div>This is rule #2</div><div>0.03</div></div><div><br></div><div>I used the salience to set rule order to be sure that rule one is executed before rule two, but my global value is never updated.<br>Can you please tell me where I do wrong? Can my expectations be met somehow, I need such type of internal rule variables to calculate temporary &nbsp;values and pass them between rules?<br></div><div><br></div><div>Thank you!!!<br><br>Best Regards,</div><div>Milen</div></BODY></HTML>