Search code examples
initializationspreadsheetdroolsdeclare

How to declare and initialize integer variable in Decision Table?


I want to declare and initialize integer variable in Decision Table. I created a sample rule in .drl file. It's working fine but i want that rule in drool spreadsheet. Anybody know How to do it?

Sample Rule code.

rule "GoodBye1"
    salience 5
    when        
        a : Message(count == 45)       
    then            
       System.out.println("-----------------");
       int temp = a.getTemplatesFromDba("123"); 
       System.out.println("-Raj--> "+temp);   
       a.setPriority(temp);
       update(a);  
end 

Solution

  • You'll have to write it in to the Action part of your decision table. Here's one way to do it with a decision table. What suites best for your needs requires a bit more info on the details.

    Condition    | Action
    a : Message  |
    $param       | a.setPrio( a.getTemplate( $param) ); update(a);
    --------------------------
    count == 45  | "123"
    

    If you need, you can add the System.out.prinln calls in the Action block as well. If you have a lot of operations to execute, it might be better to create a helper function for that.