3 Replies Latest reply on Feb 6, 2007 2:15 PM by clandestino_bgd

    How to start this process instance?


      Dear JBPM people,

      I am wondering what it would be the best way to start process instance of process definition, which have in start-state some system action (it is not executed by human). On node-enter event some action should be triggered.

      Please look at the example below:

      <?xml version="1.0" encoding="UTF-8"?>
      <process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="simple">
       <swimlane name="admin" />
       <action name="messageActionHandler"
       <start-state name="start">
       <event type="node-enter">
       <action ref-name="messageActionHandler" />
       <transition name="to_first" to="first"/>
       <task-node name="first">
       <task swimlane="admin">
       <variable name="font" />
       <transition name="to_end" to="end"/>
       <end-state name="end"></end-state>

      As you can see, here the "start-state" does not contain task and after process instance is created, it cannot be started with:

      taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();

      like in JBPM example webapp, because exception in createStartTaskInstance() occurs, since startTask is NULL.

      If I fetch the rootToken and call signall() on it, my Action on node-enter event is not invoked.

      Token rootToken = processInstance.getRootToken();

      Just to mention, everything works fine when the start-state is executed by human, and node-enter event with my action is defined in the next state.

      Any hint?
      Thank you and regards

        • 1. Re: How to start this process instance?

          Why do you want to do this?

          Start-nodes in workflow systems often have behavior different than other nodes - they're mostly just a marker for where to start. This is carried forward from general state machines. In general, trying to pin a lot of other behavior (e.g., a task) into the start node is probably asking for trouble. Even if it works in a particular scenario in a particular release, it's unlikely to be tested very well, and hence is likely to get inadvertently broken.

          But maybe you really need it - I don't know.

          -Ed Staub

          • 2. Re: How to start this process instance?

            Oops - please ignore my earlier message - I didn't read carefully.

            Are you supposed to get an enter event on the start state?
            I would only have expected a leave event.
            Start state are usually special.
            The documentation hints that there isn't an enter event on the start node, but doesn't say it explicitly:

            When a process instance is created, a token is created for the main path of execution. This token is called the root token of the process instance and it is positioned in the start state of the process definition.

            I'm guessing a lot, but I wonder if you are trying to createStartTaskInstance() before signalling to enter the node where the swimlane is started. I suspect that you have to wait till then, based on the examples.

            -Ed Staub

            • 3. Re: How to start this process instance?


              Oops - please ignore my earlier message - I didn't read carefully.

              I mean the manual of course, so I will answer here to my questions maybe somebody will find it useful, but I do not believe so :)

              1. In the JBPM manual stands:
              Start state: supported event types: {node-leave}

              So, there is no miracle, why I could not invoke my action on "node-enter" event :)

              2. The second question related how to start process instance in generic way and to cover the situations, when your start-state is either Task-node or some wait state, can be solved with additional method in JBPMTemplate (I am using springmodules-0.7)

               * Create and start process instance
               * @author agaton
               * @param definitionId.
               * The definitionId to be started.
               * @return ProcessInstance that is created
               public ProcessInstance createStartProcessInstance(final long definitionId) {
               return (ProcessInstance)execute(new JbpmCallback() {
               public Object doInJbpm(JbpmContext context) {
               ProcessInstance processInstance = null;
               ProcessDefinition processDef = context.getGraphSession()
               if(processDef != null) {
               processInstance = (ProcessInstance)processDef.createInstance();
               if(processInstance != null) {
               return processInstance;

              So, if start-state has task (startTask!=null) createStartTaskInstance() is invoked. If opposite, rootToken is signaled.

              Thank you for ignoring my questions, apart for Mr Staub, whom I am thankful as a polite and nice person, since it helped me to realize how stupid my question was.