Wrap in in ()’s like this:

 

            $tc : TaskContext( times contains (getTimeByID(ETimeID.NOW)) )

 

I have not personally tried this exact scenario, but the concept is the same as other scenarios I use this for.  The ()’s identifies that evaluation should be used here, except that it’s not really an eval() because the contents don’t returne true/false, but rather it’s just java code to be processed, and the output can then be used in the evaluation.

 

I do this with matches like this:

 

LookupFact ( $lookupValue : value )

$sf : SomeFact ( value matches (“(?i)” + $lookupValue) )

 

 

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Hezi Stern
Sent: Wednesday, November 23, 2011 7:51 AM
To: rules-users@lists.jboss.org
Subject: [rules-users] How to use contains with a function

 

Hi all,

 

I encountered the following issue:

 

As an example TaskConectxt() holds a list of time related objects called times.

I would like to write a rule which ideally would filter the TaskContext according  to a specific time object.

The problematic restriction is that this time object is derived using a helper function (imported), in this case called getTimeByID which received as input an enum ID of a time and returns the desired time object.

 

Ideally the rule would like something like this:

 

rule "verify time"

      when

           

            $tc:                    TaskContext(times contains getTimeByID(ETimeID.NOW))

      then

            //something

end

 

unfortunately this does not work.

Is there any way to call a function with a param?

Is there a better alternative method than this one?

 

Thanks,

Hezi