You have to distinguish (i.e., read the fine print in the
documentation) between "from" and "from collect". If you want the rule
to fire individually for each collection element produced by the
expression after "from", then use "from". If, however, you want to
have it all bundled into a collection you must used "from collect".

$activeRequests : ArrayList() from collect ( Request() from
$repository.findActiveRequestsByEmployee( $user.getValue() ) )

Note that the separate eval isn't necessary. You can put this
constraint into the ArrayList pattern:
    ArrayList( size > 0 )

-W

On 27/05/2013, droolsNewbie <[email protected]> wrote:
> I need a little help with Drools eval and variable assigning.
>
> rule "check that no previously submitted requests exist"
> when
>     $user : UserFormField( name == 'employeeId', value != null )
>     $repository : Repository(  )
>     $activeRequests : List( ) from
> $repository.findActiveRequestsByEmployee(
> $user.getValue() ) # call to repository
>     eval( $activeRequests.size() > 0 )
> then
>     System.err.println(' You have active requests: ' +
> ((Request)$activeRequests.get(0)).getTitle);
>     insert(Boolean.TRUE);
> end
>
> In this rule I try to access repository and get active requests for current
> user. Rule compiles and executes without any exceptions or warnings. In
> debug mode it can be seen that repository returns non empty list and I
> expect to see console message 'You have active requests' but this doesn't
> happen. I think the problem is in this line
>
> $activeRequests : List( ) from $repository.findActiveRequestsByEmployee(
> $user.getValue() )
>
> because this rule works fine
> rule "check that no previously submitted requests exist"
> when
>     $user : UserFormField( name == 'employeeId', value != null )
>     $repository : Repository(  )
>     eval( $repository.findActiveRequestsByEmployee($user.getValue()).size()
>> 0 )
> then
>     System.err.println(' You have active requests !' );
>     insert(Boolean.TRUE);
> end
>
> So could someone point me how to solve this problem?
> Thanks!
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-eval-and-variable-assigning-tp4023977.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

Reply via email to