rule-engineilogjrules

ArrayList in ilog rules


I am working in ilog rules. I want to validate a field which is inside an array list of objects.

Like,

class Company {
    List<Employee> employee;
}

class Employee {
    String Name;
    int age;
}

Here I want to validate the age field is not negative. I have company object passed as input parameter,

definitions
    set 'Company' to 'The Company to validate' ;
    set 'Employees' to employee working for 'Company'

Now how can I iterate employee which is an arraylist and check for age validations.


Solution

  • Use the 'in' BAL construct to bind a single employee from your collection to a variable in your definitions statement, then write your validation rule for this employee.

    See the Knowledge Center / infocenter for your IBM ODM version, for instance:

    IBM Operational Decision Manager 8.6.0>Operational Decision Manager version 8.6>Decision Server Rules>Reference>Rule Designer reference>Rule languages>Business Action Language (BAL)>BAL constructs>in

    You could try something like:

    definitions 
        set 'employee' to an employee in the employees of 'the company' ; 
    if
        the age of employee is less than 0
    then
        print "Age of employee " + the name of employee + "' is negative: " + the age of employee ; 
    else
        print "Age of employee " + the name of employee + "' is OK: " + the age of employee ;