Search code examples
drools

Rules compilation error Drools action column, variable cannot be resolved


I am pretty new to Drools and exploring the capabilities drools decision tables. I have downloaded Drools 6.2.0 examples and modified the one provided for decision table. In that I want to have policy condition to be removed as shown in image below

Decision Table layout

Here policy only needs to be result object but I am getting below error.

text=Rule Compilation error policy cannot be resolved or is not a field

I am not sure what to write under first ACTION column to make it work as I have tried different values such as policy:Policy, Policy etc.

Below is the drl output I receive for the above decision table layout.

// rule values at C10, header at C5
rule "Pricing bracket_10"
    when
        Driver(age >= 18, age <= 24, locationRiskProfile == "LOW", priorClaims == "1")
    then
        policy.setBasePrice(450);
end

I have tried to check documentation but I was not able to find any way to make it working. Note that I have not modified anything in the source code of the example. Only the decision table layout in the excel is changed.

Any pointers will be helpful.


Solution

  • You need to have an object of class Policy bound to a variable policy. One possibility is to insert a Policy object, and to have a pattern with it. The rule in DRL should look like this:

    rule "Pricing bracket_10"
    when
        Driver( age >= 18, age <= 24, locationRiskProfile == "LOW", priorClaims == "1")
        policy: Policy()
    then
        policy.setBasePrice(450);
    end
    

    In a decision table you could use a condition column as show below:

    CONDITION
    policy: Policy()
    /*$param*/
    match a Policy fact
    x
    

    You'll need an 'x' in each row, or join cells to make do with a single 'x'.