Search code examples
javadroolsdecision-tree

How to write drool rules in .excel for second field dependent on first fileds selection and third field dependent on second fields selection


I am very new to drool rules. I have four fields, for which I want to write drools rules in excel. Scenario is, based on selection of product, values for customerType will be populated and based on selection of customerType, values for SubProduct will be populated. And so on.

enter image description here

For eg. For any product selected then customerType 260 and 262 will be returned. but, Now if someone selects customerType 260 then subProduct will be returned as '001','002','004'. Now if someone selects subProduct as 002 then LoanPurpose should be 05

enter image description here

I have tried this. But since I am very new to this. I don't know how to write this properly.


Solution

  • I can't read the spreadsheet in your second photograph very well, but your explanation immediately before it is not particularly complex.

    Don't think of these rules as "user selects this, then this, then this." Instead, think of "when all these conditions are true, then perform this action".

    So, we want a rule like:

    • When
      • customerType == "260" AND
      • subProduct == "002"
    • Then
      • set LoanPurpose to "05"

    So you'd have:

    | CONDITION              | CONDITION            | ACTION                       |
    | agent: AhflAgentModel                                                        |
    | customerType == $param | subProduct == $param | agent.setLoanPurpose($param) |
    |------------------------|----------------------|------------------------------|
    | "260"                  | "002"                | "05"                         |
    

    Then you'd add additional rows for other customerType / subProduct combinations. Or, if there are additional conditions which may be set, you could add additional columns for those conditions.

    There are no "users" interacting with your decision table -- you pass data in, Drools evaluates the conditions and performs actions as appropriate, and you get your result. So you can't really think about users "selecting" anything. If there are users involved, then every time they do an action, you re-fire your rules and evaluate again -- but that's outside of the decision table entirely.