It doesn't work...<br><br>I tried this rule using version 3.1M1<br><br>rule "orCondition"<br> when<br> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :<br>field3) or MyObject(field1 == "b", $field2 : field2, $field3 :
<br>field3)) //correct column<br> AnotherPattern( attr2 == $field2, attr3 == $field3 )<br><div style="direction: ltr;"><span class="q"> then<br> System.out.println("fields = "+ field2 + field3);
<br></span></div>end<br><br>and I got this exception, that is the same exception received using 3.0.5 version:<br><br>Exception in thread "main" org.drools.rule.InvalidRulePackage: Duplicate declaration for variable '$field2' in the rule 'orCondition'
<br>Duplicate declaration for variable '$field3' in the rule 'orCondition'.<br><br><br>I tried also the first solution proposed, for the 3.0.5 version:<br><br>rule "orCondition"<br> when<br> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
<br>field3) or MyObject(field1 == "b")) //correct column<br> AnotherPattern( attr2 == $field2, attr3 == $field3 )<br> then<br> System.out.println("fields = "+ field2 + field3);<br>end
<br><br>..but I got this exception:<br><br>Exception in thread "main" org.drools.rule.InvalidPatternException: Required Declarations not bound: '$field2<br> at org.drools.reteoo.ReteooBuilder.checkUnboundDeclarations
(Unknown Source)<br> at org.drools.reteoo.ReteooBuilder.addRule(Unknown Source)<br> at org.drools.reteoo.ReteooBuilder.addRule(Unknown Source)<br> at org.drools.reteoo.ReteooRuleBase.addRule(Unknown Source)<br> at
org.drools.common.AbstractRuleBase.addPackage(Unknown Source)<br> at org.drools.jsr94.rules.admin.RuleExecutionSetImpl.<init>(Unknown Source)<br> at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet
(Unknown Source)<br> at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)<br> at org.drools.jsr94.rules.admin.RuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
<br><br><div><span class="gmail_quote">2007/3/13, Edson Tirelli <<a href="mailto:tirelli@post.com">tirelli@post.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> Francesco,<br><br> You need to be careful when doing that, if you are using 3.0.x version.<br> First thing is that both sides of your "or" must be perfectly<br>"balanced", i.e., the same classes in the same order. I didn't tried
<br>that, but I think it works if you simply declare your binding once:<br><br>rule "orCondition"<br> when<br> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :<br>field3) or MyObject(field1 == "b")) //correct column
<br> AnotherPattern( attr2 == $field2, attr3 == $field3 )<br> then<br> System.out.println("fields = "+ field2 + field3);<br>end<br><br> This is a workaround for the 3.0.x versions.Try it and let me know plz.
<br><br> In 3.1M1 and later, all this is fixed and the correct is to declare<br>the variable in all logical branches:<br><br>rule "orCondition"<br> when<br> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
<br>field3) or MyObject(field1 == "b", $field2 : field2, $field3 :<br>field3)) //correct column<br> AnotherPattern( attr2 == $field2, attr3 == $field3 )<br> then<br> System.out.println("fields = "+ field2 + field3);
<br>end<br><br> []s<br> Edson<br><br><br>Francesco Campagnola wrote:<br><br>> Hi,<br>><br>> I'd like to write a rule that contains an OR condition in the LHS, to<br>> match the presence in the working memory of an object with particular
<br>> values of a specific field. In the rest of LHS, i need to bind other<br>> values of the specific object matched. Is there a particular sintax to<br>> use for the binding?<br>><br>> For example:<br>>
<br>> rule "orCondition"<br>> when<br>> myObj : (MyObject(field1 == "a") or MyObject(field1 ==<br>> "b")) //correct column<br>><br>> field2: myObj.getField2
() // how to correctly get<br>> field3: myObj.getField3() // those values?<br>> then<br>> System.out.println("fields = "+ field2 + field3);<br>><br>> Thanks in advance, FC.
<br>><br>>------------------------------------------------------------------------<br>><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>><br><br><br>--<br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer
<br> Office: +55 11 3124-6000<br> Mobile: +55 11 9218-4151<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br><br><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div>
<br>