cancel
Showing results for 
Search instead for 
Did you mean: 

serviceTask field types

h_ter_schuur
Champ in-the-making
Champ in-the-making
I am looking for a possibility to implement a serviceTask which should be able to create objects with arbitrary properties. I would like to have these properties injected as Map into my serviceTask expression.

For example I want to define this in my process definition like:
<serviceTask id="javaService" name="Java service invocation" activiti:class="org.activiti.examples.bpmn.servicetask.CreateObject">
  <activiti:field name="objectType" stringValue="dummy"/>
  <activiti:field name="properties">
    <activiti:map>
      <activiti:entry key="key0"><activiti:string>Hello World</activiti:string></activiti:entry>
      <activiti:entry key="key1"><activiti:expression>Hello ${gender == 'male' ? 'Mr.' : 'Mrs.'} ${name}</activiti:expression></activiti:entry>
    </activiti:map>
  </activiti:field>
</serviceTask>

My service task implementation would be like this:

public class CreateObject implements JavaDelegate {
  …
  private Expression objectType;
  private Expression properties;

  public void execute(DelegateExecution execution) {
    String type = (String) objectType.getValue(execution);
    Map props = (Map)properties.getValue(execution);

    myRepository.addNode(type, props);
  }
}


As far as I know, currently only activiti:string and activiti:expression are supported. Are there any plans for supporting such a serviceTask field type.
Or should I use a different implementation strategy?
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
No, that's not possible at this moment.

You could create the map in a script task or execution listener up front and then inject that variable with an expression.