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 <sreeram.vadlamudi@wellsfargo.com> 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
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users