1 Reply Latest reply on May 14, 2013 2:43 AM by swiderski.maciej

    Use rule to decide flow of process

    mylos78

      Hi all !

      I'm trying to integrate some Drool Rules in a simple process. Basically I'm creating an user class which has some properties:

       

      User user = new User("George",50);

           

      Map<String, Object> params = new HashMap<String, Object>();

      params.put("user", user);

       

      ProcessInstance processInstance = ksession.createProcessInstance("DemoProcess", params);

       

      ksession.insert(processInstance);

      ksession.insert(user);

      ksession.startProcessInstance(processInstance.getId());

      ksession.fireAllRules();

       

      When the process is started, there is a Gateway with the following rule in it:

       

                       --------- Node X

      [Start] -----X

                       --------- Node Y

       

      The Rules in the Gateway(X) are:

      user.IsAdult   -->Go to Node X

      !user.IsAdult  -->Go to Node Y

       

      The problem is that the condition is always evaluated to Y because the Rule that sets isAdult seems to be evaluated later (when the process already passed that Gateway)

       

      rule "check user"

         no-loop

      when

      $p: User( age > 18)

      $pi: WorkflowProcessInstanceImpl($user: variables['user'])

      then

      $p.setIsAdult(true);

       

      $pi.setVariable("user", $p);

       

      update($p);

      end

       

      Is there something I am missing in my process ????

      Thanks a lot

      Mylos