cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning a dynamic assignee to a user task getting error

antonylees
Champ in-the-making
Champ in-the-making
Hi all

I am trying to assign a dynamic user to a user task using spring, similar to the example in the user guide.  If I take the example as the example here:

<userTask id="task" name="My Task" activiti:assignee="${ldapService.findManagerForEmployee(emp)}"/>

However, when I start the process instance, it goes directly to that usertask (via a service task) and can't locate the 'emp' property resulting the exception:

org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'emp'

How can I set the 'emp' property before it gets to the user task?  Is there some way of creating a process instance but not start it so I can set the property?

Antony
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
Hi,

You can either pass the 'emp' value when starting the process, in the variable map

runtimeProcess.startProcessInstanceByKey('processKey', variables)

or set the variables in an execution-listener when the process starts:

<process id="executionListenersProcess">
 
    <extensionElements>
      <activiti:executionListener class="org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne" event="start" />
    </extensionElements>
   
    <startEvent id="theStart" />
    <sequenceFlow sourceRef="theStart" targetRef="firstTask" />
    ….

public class ExampleExecutionListenerOne implements ExecutionListener {

  public void notify(ExecutionListenerExecution execution) throws Exception {
    execution.setVariable("variableSetInExecutionListener", "firstValue");
    execution.setVariable("eventReceived", execution.getevent());
  }
}
http://activiti.org/userguide/index.html#executionListeners

antonylees
Champ in-the-making
Champ in-the-making
Excellent! You guys have thought of everything  Smiley Happy

Thank you!