Yes, this is syntactically correct, but it sure looks strange.<br><br>In your Java code, you have <br>   AssertionObject assertionObject);<br>and this contains a list of BillingRecord where the property stationNo should not be null, then *normally* one would do<br>
   for( Object o: assertionObject.getValidationObjects() ) {  # assuming these are what $ao.get(...) returns<br>      ksession.insert( o );<br>   }<br><br>and this would let you write a simple rule like<br>   rule CheckStationNumber<br>
   when<br>       BillingRecord( stationNo == null )<br><div class="im">  
then<br>       error(&quot;station number should not be null&quot;,log);<br>   end<br></div><br>-W<br><br><br><div class="gmail_quote">2009/8/1 Abarna Ramachandran <span dir="ltr">&lt;<a href="mailto:rabarna@archstone.in">rabarna@archstone.in</a>&gt;</span><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 found my answer. Yes we can use the function in the LHS. and we can use the fact as a parameter for function. Here is how my rule looks like now<br>
rule CheckStationNumber<br>when<br>   $ao:AssertionObject()<div class="im"><br>   eval((getRecord($ao).getStationNo()) == null)<br>
then<br>    error(&quot;station number should not be null&quot;,log);<br>end<br><br></div>where getRecord($ao) is the function i define in my rule and AssertionObject is the fact i insert into my ksession. <br><br>thanks<br>
<font color="#888888">Abarna</font><div><div></div><div class="h5"><br>
<br><br><div class="gmail_quote">On Sat, Aug 1, 2009 at 5:27 PM, Abarna Ramachandran <span dir="ltr">&lt;<a href="mailto:rabarna@archstone.in" target="_blank">rabarna@archstone.in</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 really appreciate your help. I understand my mistake. I have another question. Can i use a fact as a parameter for function defined in the rule and make a call to that function in the when part of the rule.<br>For example something like this<br>


rule CheckStationNumber<br>when<br>  AssertionObject(getRecord(AssertionObject).getStationNo() == null)<br>then<br>    error(&quot;station number should not be null&quot;,log);<br>end <br><br>thanks<br>Abarna<br><br><div class="gmail_quote">


2009/8/1 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


The global ao must be assigned to the ksession, from your Java code, by calling<br>   ksession.setGlobal( &quot;ao&quot;,  assertionObject )<br>before you do anything that triggers LHS evaluations. See Drools Expert, section 4.5.2.<br>



<br>The WM and rule setup as you present it does not make sense (to me). If you insert an AssertionObject as a WM fact, you shouldn&#39;t have it as a global. If you want it as a fact, you&#39;ll need rules with patterns like<br>



when<br>   AssertionObject(...)<br>And the same goes for BillingRecord<br><br>-W<br><br><br><div class="gmail_quote">2009/8/1 Abarna Ramachandran <span dir="ltr">&lt;<a href="mailto:rabarna@archstone.in" target="_blank">rabarna@archstone.in</a>&gt;</span><br>



<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>I am getting the following error when trying to insert my object into ksession. I have attached my rules and java object. Please help me in debugging why this is happening. I am using java 5 and drools 5.0<br>



<br>thanks<br>
<br><b>error while inserting:</b><br><br>org.drools.RuntimeDroolsException: <br>defaultpkg.Rule_CheckStationNumber_0Eval0Invoker@e4aea391 : java.lang.NullPointerException<br><br><b>rules.drl</b><br>import java.lang.*;<br>




import java.util.*;<br>import ct.fw.rules.*;<br>import ct.fw.utils.*;<br>import ct.fw.rules.*;<br>import ct.fw.logging.*;<br>import ct.fw.pf.dbi.*;<br>import ct.fw.pf.dao.*;<br>import ct.fw.pf.seq.*;<br>import ct.fw.pf.util.*;<br>




import ct.fw.pf.vo.*;<br>import ct.fw.ex.*;<br>import org.apache.commons.lang.*;<br>import com.aa.gccp.domain.*;<br><br>   global ct.fw.rules.AssertionObject ao<br>   global ct.fw.logging.SmartLogger log<br>        <br>    function BillingRecord getRecord(AssertionObject ao) <br>




        {<br>            return (BillingRecord) ao.get(0);<br>        }<br>    function void debug(String msg,SmartLogger log)<br>        {<br>            log.debug(BusinessRulesValidator.class, msg);<br>        }<br>    function void error(String msg,SmartLogger log)<br>




        {<br>            log.error(BusinessRulesValidator.class, msg);<br>            System.out.println(&quot;Message from rules &quot;+msg);<br>        }<br>  <br>rule CheckTrue<br>when<br>   eval(true)<br>then<br>    System.out.println(&quot;evaluating true&quot;);<br>




end<br><br>rule CheckTrue2<br>when<br>   eval(true)<br>then<br>    error(&quot;evaluating from rules2&quot;,log);<br>end<br><br>rule CheckStationNumber<br>when<br>   eval(((getRecord(ao)).getStationNo()) == null)<br>then<br>




    error(&quot;station number should not be null&quot;,log);<br>end <br><br><b>part where i load the rules and insert the facts. There is no error when loading the rules.drl. That means no parsing errors. The error happens at ksessio.insert(assertionObject).</b><br>




<br>public void assertRulesObject(AssertionObject assertionObject) throws BusinessRuleException<br>    {<br>        long current = System.currentTimeMillis();<br>        KnowledgeBase kbase = knowledgeBasesMap.get(rulesFileName);<br>




<br>        if (kbase == null)<br>        {<br>            kbase = knowledgeBasesMap.get(rulesFileName + DRL);<br>        }<br><br>        if ((kbase == null) || ((current - lastRefreshedMilliseconds) &gt; refreshTimeMilliseconds))<br>




        {<br>            if (rulesFileName.toLowerCase().indexOf(DRL) == -1)<br>            {<br>                kbase = load(rulesFileName + DRL);<br>            }<br>            else<br>            {<br>                kbase = load(rulesFileName);<br>




            }<br><br>            lastRefreshedMilliseconds = System.currentTimeMillis();<br>        }<br>        this.assertionObject = assertionObject;<br><br>        List assertionobjectslist = new ArrayList();<br><b>// i am just doing this part just to make sure assertion object is not null and i will get some answer. this part runs fine.  </b>    <br>




  if (assertionObject != null)<br>        {<br>            assertionobjectslist = assertionObject.getValidationObjects();<br>            String StationNumber = ((BillingRecord) assertionObject.get(0)).getStationNo();<br>



            System.out.println(&quot;Station Number in assertion object is &quot; + StationNumber);<br>
        }<br>        else<br>        {<br>            System.out.println(&quot;Assertion Object is null&quot;);<br>        }<br>        System.out.println(&quot;The number of objects in assertionobject is &quot; + assertionobjectslist.size());<br>




<br>        try<br>        {<br>            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br><b>//the next line throws the exception</b><br>            ksession.insert(assertionObject);<br><br>



            ksession.fireAllRules();<br>
            ksession.dispose();<br><br>        }<br>        catch (RuntimeDroolsException e1)<br>        {<br>            throw new BusinessRuleException(e1.getMessage());<br>        }<br><br>        businessRulesErrors = assertionObject.getBusinessRulesErrors();<br>




<br>        if (throwException)<br>        {<br>            if (!assertionObject.getBusinessRulesErrors().isEmpty())<br>            {<br>                throw new BusinessRuleException(businessRulesErrors);<br>            }<br>




        }<br>    }<br><br><br>Any help is appreciated. thanks<br><br>
<br></div></div><div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></div></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><br>
</blockquote></div><br>
</div></div><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>
<br></blockquote></div><br>