2 Replies Latest reply on Jul 9, 2014 12:52 PM by Charlie Wang

    How to execute business rule from specific rules node

    Charlie Wang Newbie

      Hi everyone,


      I currently have a process workflow setup with start -> service task -> script task -> business rule -> script task -> end.

      I have created the service task using the CustomWorkItem.wid and drools.rulebase.conf files.

      I have created a rule file named newRule.drl.

      In my main I created the run time enviorment and added the class path resource of both my process .BPMN and my .DRL.
      Afterwards I used:




      And this allows me to fire the rules during my process.


      How can I only allow the process to execute my business rules when the business rule node is hit? Instead of just executing the rule base at the end? Currently, regardless of where I place my business rules node my newRules.drl is executed at the end and not where I want it to.

      I am currently using the eclipse jBPM pluggin instead of the KIE workbench so some of the workbench tutorial attributes I do not have in my specific rules node, I only have the rule group that it is assigned to.

      I understand from the screencast that I saw that I have to assign variables of the process to my rule task such as input and output variables in order to execute the ruletask node at that time. The ruletask node that I have on eclipse is only showing an "on-entry" and "on-exit" script and nothing even talks about assigning variables.


      Thanks for all your help!

        • 1. Re: How to execute business rule from specific rules node
          Maciej Swiderski Master

          business rule task will fire all rules from defined ruleflow group if they are activated - activation means there are matching facts in ksession so rules can execute. What is most likely happening in your case is that you activate rules after your process has been completed because you insert facts after starting process. So if you change the order of method invocation on ksession to be like this:

          - ksession.insert

          - ksession.startProcess


          then your rules will be fired from within process instance and no need to have explicit call to ksession.fireAllRules


          In addition, declaration of inputs/outputs on business rule task is not mandatory and is only used to insert/delete facts before/after executing business rule task node.



          • 2. Re: How to execute business rule from specific rules node
            Charlie Wang Newbie

            Thanks for your reply Maciej!


            I have rules in my .drl file that corresponds to the objects that I inserted with ksession.insert. For example:

            ksession.insert(Person); where Person has the variable age.


            rule "age less than 10"


            $age: (Person > 10)


                 System.out.println("Greater than 10");



            Is this what you mean by activated? As in the facts of the rules are matching the object? I reorganized the insert and startprocess commands but now instead of executing the rules the ruletask node is skipped completely...