<div>You could do something like this:</div><div><br></div>rule 'empty documents'<div>...</div><div>when</div><div> $emptyDocs: List(size>0) from collect ( <span style>Document( field1== null || == ( "" ) , field2 == null || == ( ""</span><span style>) ) )</span></div>
<div><font color="#222222" face="arial, sans-serif">then</font></div><div><font color="#222222" face="arial, sans-serif"> </font><span style> //insert an error</span></div><div><span style> Error fact0 = new Error();</span></div>
<span style> fact0.setErrorCode( "code1" );</span><br style><span style> insert(fact0 );</span><br style><span style> </span><div><font color="#222222" face="arial, sans-serif"> //retract empty documents</font></div>
<div><font color="#222222" face="arial, sans-serif"> for (int i=0; i < $emptyDocs.size(); i++){</font></div><div><font color="#222222" face="arial, sans-serif"> </font><span style>retract( $</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">emptyDocs.get(i)</span><span style>);</span></div>
<div><font color="#222222" face="arial, sans-serif"> }<br></font><div><span style> </span><div><font color="#222222" face="arial, sans-serif">end<br clear="all"></font><br><br>Best Regards,<br><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
<br>Esteban Aliverti<br>- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com </a><br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
<br><br><div class="gmail_quote">On Thu, Feb 2, 2012 at 9:59 PM, vadlam <span dir="ltr"><<a href="mailto:sreeram.vadlamudi@wellsfargo.com">sreeram.vadlamudi@wellsfargo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
<br>
we have a scenario whereby, several documents are created as part of the<br>
ruleflow. at the end of the ruleflow, if any of the fields in the document<br>
is empty or null, we would like to create a error (only one error) and<br>
retract all the documents so far.<br>
<br>
rule "createError"<br>
ruleflow-group "mrHardErrors"<br>
no-loop true<br>
dialect "mvel"<br>
<br>
when<br>
<br>
<br>
emptyDoc : Document( field1== null || == ( "" ) , field2 == null || == ( ""<br>
) )<br>
doc : Document( )<br>
then<br>
<br>
Error fact0 = new Error();<br>
fact0.setErrorCode( "code1" );<br>
insert(fact0 );<br>
retract( emptyDoc);<br>
<br>
end<br>
<br>
I see that error is created more than once ( as many as matching documents )<br>
<br>
How do we ensure that all documents are retracted and also the error is<br>
created only once ?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/how-to-retract-all-documents-created-in-the-following-scenario-tp3711226p3711226.html" target="_blank">http://drools.46999.n3.nabble.com/how-to-retract-all-documents-created-in-the-following-scenario-tp3711226p3711226.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></span></blockquote></div><br></div></div></div>