Conditions are evaluated when facts are inserted, modified and deleted.
-W


2011/8/25 Matthew Erler <wires8@yahoo.com>
In Drools 5 I'm passing in two global Date objects and need to find the difference in days between them.  I've discovered that the function parameters (fromDate and toDate in my case) are null in the condition when the function is called, but when the function is called in the consequence they have values.  I can see that because the output of the following rule is:
fromDate is null
toDate is null
I'm in dateDiff and the date diff is: 14

I'm guessing that Drools doesn't make globals t available at the point that I need them.  Can anyone confirm this and offer a solution?

Here is the rule file itself:

import java.util.Date;
import org.joda.time.DateMidnight;
import org.joda.time.Days;

global java.util.Date fromDate;
global java.util.Date toDate;


rule "dateDiff"
dialect "mvel"
     when
          eval(getDaysBetweenStartAndEndDate(fromDate, toDate) < 10)
     then         
          System.out.println( "I'm in dateDiff and the date diff is: " +        getDaysBetweenStartAndEndDate(fromDate, toDate));              
end


function int getDaysBetweenStartAndEndDate(Date fromDate, Date toDate) {
    if (fromDate==null) System.out.println("fromDate is null");
    if (toDate==null) System.out.println("toDate is null");
  return Days.daysBetween(new DateMidnight(fromDate), new DateMidnight(toDate)).getDays();
}

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users