3

I'm trying to build a simple rule on KIE Workbench/Drools in a new DRL file and I keep getting the following error on build & deploy

Rule Compilation error name cannot be resolved to a variable Syntax error, insert ";" to complete Statement

here's the code:

package demo.people.peopleproject
import demo.people.peopleproject.Person

rule "is18rule"
    when 
        Person(age>=18)
    then
        System.out.println(name  + "is 18 or over")
end

and here's a screenshot of my work bench if helpful enter image description here

I'm new to Drools, TIA for your help :)

EDIT: I should add that simply adding a ; really anywhere here hasn't helped, so, yes, I have tried that

toha
  • 5,095
  • 4
  • 40
  • 52
tls11
  • 73
  • 1
  • 1
  • 7
  • the RHS of the rule is Java so you need ; to complete statements. – tarilabs Sep 29 '16 at 11:48
  • as to what concerning the "name" field of the matched Person, you could do as per your own answer, or alternatively, bind the variable as `Person( $name : name ,...)` in the LHS, and then reference in RHS as `$name`. – tarilabs Sep 29 '16 at 11:50

2 Answers2

3

I found the answer- if helpful to anyone in the future- here's the code that ended up working for me. Needed semicolons and slightly different syntax.

package demo.people.peopleproject
import demo.people.peopleproject.Person;

rule 'is18rule'
    when 
        p: Person(age >= 18)
    then
        System.out.println(p.getName() + "is 18 or over.");
end
tls11
  • 73
  • 1
  • 1
  • 7
0

In drools, you need semi-colons for every statement in the consequence (RHS) [edit] . Java rules also apply to imports and package declarations in general.

Pitty that workbench does not provide realtime syntax validation.

PeabeaM
  • 61
  • 8