8 Replies Latest reply on Aug 27, 2007 2:04 AM by cheets

    next task/node name in processInstance

    cheets

      Hi all,

      Sorry if it is a basic question, but I can't figure out how to get the name of the next task in a process instance.
      I have a taskinstance, which I just end on the click of a button (it is a approve/reject kind of task), but after doing task_instance.end(), how can I find out which is the next task in the processInstance?

      As an aside, this particular task is part of a fork, and the next task is assigned only after the join. In this case, will I get the join node as the next node?

      I am not using swimlanes, since different actors are performing different tasks.
      thanks in advance..

        • 1. Re: next task/node name in processInstance
          kukeltje

          may I ask why you want to do this, maybe there are other solutions to your 'functional problem'

          • 2. Re: next task/node name in processInstance
            cheets

            Hi Ronald,
            thanks for ur reply. I am integrating jbpm workflow with spring based webapp. So in the form controllers, I have to send data to the jsp based on which way the task ended (the command buttons for the next task based on permissions for the user). That's why i need the next task's name. If there are other approaches for this, please advice?
            thanks again...

            • 3. Re: next task/node name in processInstance
              vtysh

              You can try to use jbpm logs. But i don't know which results will you get in case of the next node is the join node. Here how it is used in TaskBean.java of jbpm-3.1.3

               LoggingInstance loggingInstance = processInstance.getLoggingInstance();
               List assignmentLogs = loggingInstance.getLogs(TaskAssignLog.class);
              
               log.debug("assignmentlogs: " + assignmentLogs);
              
               if (assignmentLogs.size() == 1) {
               TaskAssignLog taskAssignLog = (TaskAssignLog) assignmentLogs.get(0);
               JsfHelper.addMessage("A new task has been assigned to '" + taskAssignLog.getTaskNewActorId() + "'");
              
               } else if (assignmentLogs.size() > 1) {
               String msg = "New tasks have been assigned to: ";
               Iterator iter = assignmentLogs.iterator();
               while (iter.hasNext()) {
               TaskAssignLog taskAssignLog = (TaskAssignLog) iter.next();
               msg += taskAssignLog.getActorId();
               if (iter.hasNext())
               msg += ", ";
               }
               msg += ".";
               JsfHelper.addMessage(msg);
               }
              

              TaskAssignLog has reference to TaskInstance

              • 4. Re: next task/node name in processInstance
                cheets

                Hi vtysh,
                thanks for this new approach, but i am wondering whether it is an accepted practice to base program logic on logs.
                Also, this approach leaves me with 2 questions.. TaskAssignLog has a constructor with taskInstance, oldActorId and new ActorId; so if i know only the task instance, and the new actor id, how can i access the taskAssignLog of my taskInstance.
                The other doubt is that this will give me all the task related logs for the given processInstance, this still will not give me the next task for that particular task, or am i missing something?
                please elaborate..
                thanks!

                • 5. Re: next task/node name in processInstance
                  vtysh

                  It will give you next assigned and open task(s). Use this code after ending of taskInstance.
                  You can download jbpm 3.1.* and see how it is used in jbpm web application.

                  • 6. Re: next task/node name in processInstance
                    kukeltje

                    knowing which button was used to end a task is something different than knowing what the next task is. I still do not get why you need this and can therefor not propose a different solution

                    • 7. Re: next task/node name in processInstance
                      cheets

                      sorry for not being more clear, but my scenario is like this.. A user performs some action to finish a task on one webpage. In the java side, I capture what action the user performed, modify the task accordingly (set variables, etc), end it and close the context.

                      now, to decide which page to show next, i need to know what the next task is going to be. I retrieve the same processInstance from the tables, and find out the current unfinished tasks, but it gives me the same previous task as unfinished when i use jbpmtemplate.findProcessInstance(processId), although the database has been updated with the new task status.
                      I resolved this problem by using jbpmcontext.loadProcessInstance(processId), which gives me an updated data set from the database.
                      (why did this happen, is this expected behavior?)

                      I realize now that getting the next task is not possible as such, because a task may end and then fork into multiple tasks, or go into wait for join, in both cases, something like task.nextTask is not possible to retrieve. am i right?
                      thanks for all the replies!

                      • 8. Re: next task/node name in processInstance
                        cheets

                        i forgot to add that jbpmtemplate.findProcessInstance() gives updated values when a new request is sent (ie, when i navigate back to my current page from some other page), it only fails to update when i want to refresh data on the same page, and the new page values for task are computed in the same function.

                        As an aside, i get the taskInstances from the processInstance, and iterate over the collection to find those which match my criteria (end is null, actor id is current user, task name is ABC etc) to identify the reqd task.
                        Hope this makes things clearer...