How to add modeler workspace extensions properties through java api

I’m trying to create a model through java api where i’m able to create the basic model as bellow:

val modelInstance: BpmnModelInstance = Bpmn.createProcess(fileName.toLowerCase)
.executable()“start”).name(“Start Event”)“ut”).name(“User Task”)“end”).name(“End event”)

Here,i wish to add a property in extensions of modeler workspace.Can any one help me with this!!!

@Sagari_E here is some code i have used for this type of thing.

I just tested it out and it works for setting the mode. I did not know this, but apparently the Definition ID of the BPMN model is considered a ModelElement, so can reuse the same code to add Extension Elements to Activities!

    private CamundaProperties createCamundaProperties(BpmnModelInstance bpmnModelInstance, Map<String,String> properties) {
        CamundaProperties camundaProperties = bpmnModelInstance.newInstance(CamundaProperties.class)
        properties.each {
            camundaProperties.addChildElement(addCamundaProperty(camundaProperties, it.getKey(), it.getValue()))
     return camundaProperties

    private CamundaProperty addCamundaProperty(CamundaProperties properties, String key, String value){
        CamundaProperty property = properties.getModelInstance().newInstance(CamundaProperty.class)
        return property

    BpmnModelInstance addCamundaProperties(BpmnModelInstance bpmnModelInstance, List<String> elementIds, Map<String, String> properties ){
        elementIds.each { elementId ->
            ModelElementInstance instance = bpmnModelInstance.getModelElementById(elementId)
            try {
                CamundaProperties camundaProperties = createCamundaProperties(bpmnModelInstance,properties)
            } catch (all){
                throw new Exception("Cant add extension to Element: ${elementId}.  Error: ${all}")

        return bpmnModelInstance

    BpmnModelInstance model3() {

        BpmnModelInstance model = Bpmn.createExecutableProcess('model')
                .name("Reminder Demo")
                .manualTask('manual1').name('do something')
                //.moveToActivity('killusertask').connectTo('manual1') This does not work. Must use the moveToNode()
                .manualTask('manual2').name('do something else')
        model = addCamundaProperties(model,
                                    ['model','someStartEvent','killusertask', 'readEmail'],
                                    ['prop1':'value1', 'prop2':'value2'])
        return model

So at the bottom you see a fancy BPMN Fluent API model.

Once the core model is built, you need to add your extension elements to your activities (or in your case the Model).

So you can call addCamundaProperties(model, elements[], properties[:])

Note that you need to add id values to each of the elements you want to attach to.

In your specific case you wanted to add it to the Definition, so you use the Definition Id as your elementId

@thorben @camunda as a note for Fluent API, The issue with the fluent api and adding extensionElements, is to create a extension element using the core classes, you need the model instance that is part of the builder. Would be nice if there was a helper method accessible inside of the builder that let you pass the current mode into another method to generate the extension element.

1 Like