Search code examples
droolsbusiness-rules

Drools Collection Iteration


what's Wrong with this rule.

rule "Organization Employee Rule"
    when

        $company: CompanyFact( $emp: /employeeList{organizationName== "XYZ"})

    then
        System.out.println("Employee in organization" +$emp);
end

I am getting this error while trying to run this rule.

[ERR 102] Line 23:44 mismatched input '{' in rule "Organization Employee Rule"

CompanyFact has list of Employee and Employee has String organization name.


Solution

  • If you are using Drools 7.x, they changed the OOPath syntax to make it closer to XPath.

    Try to use square brackets instead of curly ones:

    rule "Organization Employee Rule"
    when
        $company: CompanyFact( $emp: /employeeList[organizationName== "XYZ"])
    then
        System.out.println("Employee in organization" +$emp);
    end
    

    Hope it helps,