4 Replies Latest reply on Jul 20, 2007 10:17 AM by jgreiner

    Some questions on Process Instance.

    jgreiner

      I just wanted to make sure I am doing some things using the best practice. I think I am doing some things that are not just 100% correct and work coincidentally

      I have the process instance that I want to work with. What is the best method to get a Node so I can signal it? Also what is the best method to get a task so I can end it?

      My Logic I am using on Node is....

       ProcessInstance pi = jbpmContext.getProcessInstance(pid);
      
       Token token = pi.findToken("MyNode1");
       token.signal("Pass"); // transition
      


      My logic on a Task Node is...this is the one I think is not the best practice.

       ProcessInstance pi = jbpmContext.getProcessInstance(pid);
      
       Collection tis = pi.getTaskMgmtInstance().getTaskInstances();
       Iterator li = tis.iterator();
       while (li.hasNext())
       {
       TaskInstance ti = (TaskInstance)li.next();
       if (ti.getEnd() == null)
       {
       String ami = (String)ti.getVariable(ProcessVariables.ART_MASTER_ID);
       if (ami.equals(String.valueOf(artMasterId)))
       {
       ti.start(actorId);
       am = qm.retrieveArtMaster(artMasterId);
       }
       }
       }
      


      Thanks

        • 1. Re: Some questions on Process Instance.
          cahimoped

          If you are in actions you can use the ExecutionContext : executionContext.getToken and executionContext.getTaskInstance...

          • 2. Re: Some questions on Process Instance.
            jgreiner

            Thanks for your response, unfortunately I am not in an Action.

            The users has just finished the task on the web page (of my own design) and I am calling a ejb method that will then get the processinstance bia the process id and transition the task.

            Looking at source code an running some tests I have found that way I am hitting the tasks is in fact incorrect. The code will give me all tasks even completed ones which might not be good.

            • 3. Re: Some questions on Process Instance.
              cahimoped

              I think what I would try to do is get the id of the taskInstance the user is doing and directly have it in your method...

              In all cases I think you need something more to find the right taskInstance.

              • 4. Re: Some questions on Process Instance.
                jgreiner

                You know that is not a bad idea at all.....I can store the taskInstance ID on a Node-Enter event, then I can get the exact task instance every time.

                That should work just peachy.....I will try to post the code here if it all works.

                Thanks