[rules-users] how to retract all documents created in the following scenario

Esteban Aliverti esteban.aliverti at gmail.com
Thu Feb 2 17:04:27 EST 2012


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 at 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120202/614da7b1/attachment.html 


More information about the rules-users mailing list