cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Service Task and field injection

melentye
Champ in-the-making
Champ in-the-making
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
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
Expressions + variables is the way to go.

I don't get what you actually want: how would you want to change the input parameters, if you don't want to change variables? Or change anything at all?