The rule shown below isn't correct. It will create an Error, but it won't retract *all* Document facts as there may be some that do not have field1 or field2 set to null/"". -W
On 02/02/2012, Esteban Aliverti <[email protected]> wrote: > You could do something like this: > > rule 'empty documents' > ... > when > $emptyDocs: List(size>0) from collect ( Document( field1== null || == ( > "" ) , field2 == null || == ( "") ) ) > then > //insert an error > Error fact0 = new Error(); > fact0.setErrorCode( "code1" ); > insert(fact0 ); > > //retract empty documents > for (int i=0; i < $emptyDocs.size(); i++){ > retract( $emptyDocs.get(i)); > } > > end > > > Best Regards, > > XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > > Esteban Aliverti > - Developer @ http://www.plugtree.com > - Blog @ http://ilesteban.wordpress.com > > > On Thu, Feb 2, 2012 at 9:59 PM, vadlam > <[email protected]>wrote: > >> Hi All, >> >> we have a scenario whereby, several documents are created as part of the >> ruleflow. at the end of the ruleflow, if any of the fields in the document >> is empty or null, we would like to create a error (only one error) and >> retract all the documents so far. >> >> rule "createError" >> ruleflow-group "mrHardErrors" >> no-loop true >> dialect "mvel" >> >> when >> >> >> emptyDoc : Document( field1== null || == ( "" ) , field2 == null || == ( >> "" >> ) ) >> doc : Document( ) >> then >> >> Error fact0 = new Error(); >> fact0.setErrorCode( "code1" ); >> insert(fact0 ); >> retract( emptyDoc); >> >> end >> >> I see that error is created more than once ( as many as matching documents >> ) >> >> How do we ensure that all documents are retracted and also the error is >> created only once ? >> >> -- >> View this message in context: >> http://drools.46999.n3.nabble.com/how-to-retract-all-documents-created-in-the-following-scenario-tp3711226p3711226.html >> Sent from the Drools: User forum mailing list archive at Nabble.com. >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users >> > _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
