AnsweredAssumed Answered

Custom Service Task and field injection

Question asked by melentye on May 16, 2013
Latest reply on May 21, 2013 by jbarrez
Hi,

I have a custom service task with java delegate

public class CustomServiceTask implements JavaDelegate {

    private Expression a;

    private Expression b;

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        a.getValue(execution);
        b.getValue(execution);
    }
}


I understand that service task class will only be instantiated once and then re-used by all process instances. Does it mean that in my process definition files I cannot use this service task twice with different field values?


<serviceTask id="javaService" name="Java service invocation"
  activiti:class="CustomServiceTask">
 
  <extensionElements>
    <activiti:field name="a">
      <activiti:expression>${varA}</activiti:expression>
    </activiti:field>
    <activiti:field name="b">
       <activiti:expression>${varB}</activiti:expression>
    </activiti:field>
  </ extensionElements>
</ serviceTask>





<serviceTask id="javaService2" name="Java service invocation with other params"
  activiti:class="CustomServiceTask">
 
  <extensionElements>
    <activiti:field name="a">
      <activiti:expression>${varC}</activiti:expression>
    </activiti:field>
    <activiti:field name="b">
       <activiti:expression>${varD}</activiti:expression>
    </activiti:field>
  </ extensionElements>
</ serviceTask>


The use case is that I have a re-usable Java Service that I need to invoke multiple times during the process but with different input parameters. If I use expressions with process variables that doesn't help much: it means that I have to populate the same process variable in advance before calling the ServiceTask

Any help on this will be highly appreciated

regards,
Andrey

Outcomes