7 Replies Latest reply on Feb 9, 2010 4:08 PM by Ronald van Kuijk

    Ad hoc task creation

    Ed Loyot Newbie

      Hi All,


      I need to create tasks for a particular activity programatically. This was straightforward in jBPM 3.x but I don't see how to do this is jBPM 4. I've reviewed the docs and the API but don't see anything relevent. Can someone point me in the right direction either into the docs or into API.





        • 1. Re: Ad hoc task creation
          Sebastian Schneider Master

          It's all in the docs: http://docs.jboss.com/jbpm/v4/javadocs/


          Task task = taskService.newTask();






          Et voilà!

          • 2. Re: Ad hoc task creation
            Sebastian Schneider Master
            After re-reading your post I am not sure anymore If I got you right. So maybe you can elaborate a bit. Do you want to have a task as part of a process?
            • 3. Re: Ad hoc task creation
              Ed Loyot Newbie

              Thanks for the quick response but I need the task to be associated with a particular task node in the graph. This way when all the tasks are complete the node can transition automatically. In jBPM 3 the create new task method had a parameter to supply the graph node. In jBPM 4 there is no setter and no parameter that I can see.





              • 4. Re: Ad hoc task creation
                Sebastian Schneider Master

                Okay, since you are talking of several tasks I assume you want something like a foreach-activity which is not yet implemented:




                Please vote for the issue. Maybe you even want to contribute on this.


                Again: Please vote for the issue. This helps with prioritizing things. Lots of people don't make use of this possibililty which is a pitty.

                • 5. Re: Ad hoc task creation
                  Ed Loyot Newbie

                  Hi Sebastian,


                  This doesn't sound like what I need.


                  Specifically, I have a group of people who will need to review a document. I don't know until runtime who these reviewers will be or how many there will be, thus I cannot create the tasks in the PDL. When the review process instance is created I will know who the reviewers are and can configure a task for each one associated with the review node. Once all the review tasks have been completed the node should transition.


                  As I said, this functionality is included in 3.x but has disappeared in 4.x.


                  This was the 3.x code


                  TaskNode taskNode = (TaskNode) executionContext.getNode();
                  Task task = taskNode.getTask(this.taskName);

                  for (Person person : this.getPeopleToAssignTaskTo(version)) {
                               Token token = executionContext.getToken();
                               TaskInstance taskInstance = taskMgmtInstance.createTaskInstance(task, token);





                  • 6. Re: Ad hoc task creation
                    Ronald van Kuijk Master

                    I don't think he means the for-each construct. Ad-hoc task creation in jBPM 3 was something I used to. Task created just out of the blue, not related to the flow but part of the process.


                    In jBPM4 you can create subtasks of a task like with


                         Task t = taskService.findPersonalTasks("username").get(0);
                         Task subtask = taskService.newTask(t.getId());
                         String stId = subtask.getId();


                    But these are not fully adhoc.


                    When you create a new task that is not a subtask, you can cast it to TaskImpl and set an execution. Keep in mind that this is NOT api comformant and might (or might not) break in the future. So if there is really a use case for it, make a jira issue and gather votes to get this in the API... You'll have my vote.

                    1 of 1 people found this helpful
                    • 7. Re: Ad hoc task creation
                      Ronald van Kuijk Master
                      Ahh.. .but this IS what the foreach is for... It should be possible to have several identical tasks for different users, or several semi-identical but slightly different ones for the same user....