Hi @Ingo_Richtsmeier
Thanks for the prompt response, apologies for getting back with a delay.
I have tried as per your suggestion in the below code.
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(“testProcess”).startEvent().serviceTask(“task”).camundaClass(“com.example.Test”).endEvent().done();
final ModelElementInstance modelElement = modelInstance.getModelElementById(“task”);
final CamundaField field = modelElement.getModelInstance().newInstance(CamundaField.class);
field.setCamundaName(“injection”);
field.setCamundaExpression(“${myBean}”);
modelElement.addChildElement(field);
Bpmn.validateModel(modelInstance);
and I get the following error
Exception in thread “main” org.camunda.bpm.model.xml.ModelException: New child is not a valid child element type: field; valid types are: [documentation, extensionElements, auditing, monitoring, categoryValueRef, incoming, outgoing, ioSpecification, property, dataInputAssociation, dataOutputAssociation, resourceRole, loopCharacteristics]
at org.camunda.bpm.model.xml.impl.util.ModelUtil.getIndexOfElementType(ModelUtil.java:203)
at org.camunda.bpm.model.xml.impl.instance.ModelElementInstanceImpl.findElementToInsertAfter(ModelElementInstanceImpl.java:328)
at org.camunda.bpm.model.xml.impl.instance.ModelElementInstanceImpl.addChildElement(ModelElementInstanceImpl.java:288)
For the time being, I checked out the bpmn-model-api module from github and added the below two methods to the ServiceTaskBuilder.java
public ServiceTaskBuilder camundaField(String fieldName, String fieldValue) {
final CamundaField field = createInstance(CamundaField.class);
field.setCamundaName(fieldName);
field.setCamundaStringValue(fieldValue);
addExtensionElement(field);
return myself;
}
public ServiceTaskBuilder camundaExpressionField(String fieldName, String expression) {
final CamundaField field = createInstance(CamundaField.class);
field.setCamundaName(fieldName);
field.setCamundaExpression(expression);
addExtensionElement(field);
return myself;
}
With the above change to ServiceTaskBuilder I was able to achieve the desired outcome. Please let me know if I am missing something from your suggestion or if field injections are not coded into the builders yet.