Question

I have two facts that I am inserting into my drools session. I want to check the following:

(shipment1 != null && shipment1.shipToCustomerNo == waypoint1.shipToNumber) || shipment1 == null

How do I do add this condition in the guvnor web based decision table? I've tried using a predicate, and waypoint1 and shipment1 are bound variables that are being inserted into the session successfully. If I use the predicate and add what I have above, my test cases work fine, but when I actually run these rules in my java app, the conditions never evaluate true even though the data is equivalent. I've tried many different ways to structure this query. Below is the generated source:

//from row number: 1
rule "Row 1 Arrive Destination"
    salience 3
    activation-group "arrive-destination"
    dialect "mvel"
    when
        waypoint1 : Waypoint( type == "Destination" )
        clm1 : CarLocationMessage( sightCode == "Z" , loaded == true )
        shipment1 : Shipment( eval( (shipment1 != null && shipment1.shipToCustomerNo == waypoint1.shipToNumber) || shipment1 == null ))
    then
        TripEventRuleResult tripEventRuleResult1 = new TripEventRuleResult();
        tripEventRuleResult1.setEventType( "Arrive" );
        insert( tripEventRuleResult1 );
end
Was it helpful?

Solution

If I understood your domain and problem description correctly, you should be able to do the rule like this.

//from row number: 1
rule "Row 1 Arrive Destination"
    salience 3
    activation-group "arrive-destination"
    dialect "mvel"
    when
        waypoint1 : Waypoint( type == "Destination" )
        clm1 : CarLocationMessage( sightCode == "Z" , loaded == true )
        Shipment( shipToCustomerNo == waypoint1.shipToNumber) or
        not Shipment()
    then
        TripEventRuleResult tripEventRuleResult1 = new TripEventRuleResult();
        tripEventRuleResult1.setEventType( "Arrive" );
        insert( tripEventRuleResult1 );
end

In short, you don't need to have null check for the Shipment object. It either is or is not in the Working Memory

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top