Camunda modeler element-templates

Good afternoon Camunda,

I would like to build templates with predefined fields.
I created service task (implementation Connector) configured details in Connector tab
And now I would like to move my configuration to template and achieve the same behavior.

My schema look’s like that


First sevice task it is a connector which have to fetch some data from test api and put response into variable.
And it works fine, I could take the result from variable in the next service tasks which is external.
(process instance variables tab contains response)

My connector service task in xml view looks:

<bpmn:serviceTask id="Activity_0iger68">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="url">http://dummy.restapiexample.com/api/v1/employee/1</camunda:inputParameter>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:inputParameter name="headers">
              <camunda:map />
            </camunda:inputParameter>
            <camunda:outputParameter name="response">
              <camunda:script scriptFormat="JavaScript">S(response).prop("data")</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1y9smk0</bpmn:incoming>
      <bpmn:outgoing>Flow_0jwf2sp</bpmn:outgoing>
    </bpmn:serviceTask>

Then I tried to move all this input and output params to element template:

[
    {
        "name": "Get weather data",
        "id": "my.connector.http.get.weather",
        "appliesTo": [
            "bpmn:Task"
        ],
        "properties": [],
        "scopes": {
            "camunda:Connector": {
                "properties": [
                    {
                        "label": "ConnectorId",
                        "type": "String",
                        "value": "http-connector",
                        "binding": {
                            "type": "property",
                            "name": "connectorId"
                        }
                    },
                    {
                        "label": "Method",
                        "type": "String",
                        "value": "GET",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "method"
                        }
                    },
                    {
                        "label": "URL",
                        "type": "String",
                        "value": "http://dummy.restapiexample.com/api/v1/employee/1",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "url"
                        }
                    },
                    {
                        "label": "Response",
                        "type": "String",
                        "value": "response",
                        "binding": {
                            "type": "camunda:outputParameter",
                            "source": "S(response).prop(\"data\")",
                            "scriptFormat": "JavaScript"
                        }
                    }
                ]
            }
        }
    }
]


There is no map but as I red there is workaround for it Camunda Modeler template with Connector Scope - Defining headers - #3 by andreasmartin
Which I also tried

So my element in xml view looks:

<bpmn:task id="Activity_1u5gfs8" camunda:modelerTemplate="my.connector.http.get.weather">
      <bpmn:extensionElements>
        <camunda:connector inout="">
          <camunda:inputOutput>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:inputParameter name="url">http://dummy.restapiexample.com/api/v1/employee/1</camunda:inputParameter>
            <camunda:outputParameter name="response">
              <camunda:script scriptFormat="JavaScript">S(response).prop("data")</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_13wi79n</bpmn:incoming>
      <bpmn:outgoing>Flow_0cobpk4</bpmn:outgoing>
    </bpmn:task>

But in this implementation I don’t have response variable in next service task (process instance variables tab is empty)

Is it possible to move all configs not only for connector but in general with other elements
to template
If yes what I am doing wrong?

Thanks in advance

Kr,
Mark

Working Solution

[
    {
        "name": "Get weather data",
        "id": "my.connector.http.get.weather",
        "appliesTo": [
            "bpmn:ServiceTask"
        ],
        "properties": [],
        "scopes": {
            "camunda:Connector": {
                "properties": [
                    {
                        "label": "ConnectorId",
                        "type": "String",
                        "value": "http-connector",
                        "binding": {
                            "type": "property",
                            "name": "connectorId"
                        }
                    },
                    {
                        "label": "Method",
                        "type": "String",
                        "value": "GET",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "method"
                        }
                    },
                    {
                        "label": "URL",
                        "type": "String",
                        "value": "http://dummy.restapiexample.com/api/v1/employee/1",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "url"
                        }
                    },

                    {
                        "label": "Response",
                        "type": "String",
                        "value": "response",
                        "binding": {
                            "type": "camunda:outputParameter",
                            "source": "S(response).prop('data')",
                            "scriptFormat": "JavaScript"
                        }
                    }
                ]
            }
        }
    }
]

Hi Mark,

Your template looks good to me, but you might need to escape your OutputParameter-Script ( \ " )
Additionally I recommend to format your posts here according to the style-guidlines (e.g. code-tags ` ` ` for your xml/json) to make your questions more readable.

1 Like

Hi @KeyKon

Thank you for you response.
I updated my main message with correct styles.
I tried you suggestion:

 <camunda:script scriptFormat="JavaScript">\S(response).prop('data')</camunda:script>

But it didn’t help, also one another approach with script which also didn’t help
I also double checked if it do api call and yes it do
So connector has a response but still didn’t bind it to property

Kr,
Mark

Hm, I wonder if the problem might be that your template refers to all bpmn.Task instead of just bpmn.ServiceTask

Did you already try this:

"appliesTo": [
      "bpmn:ServiceTask"
]
1 Like

Yes, now it work’s

Thank you.

Working Solution

[
    {
        "name": "Get weather data",
        "id": "my.connector.http.get.weather",
        "appliesTo": [
            "bpmn:ServiceTask"
        ],
        "properties": [],
        "scopes": {
            "camunda:Connector": {
                "properties": [
                    {
                        "label": "ConnectorId",
                        "type": "String",
                        "value": "http-connector",
                        "binding": {
                            "type": "property",
                            "name": "connectorId"
                        }
                    },
                    {
                        "label": "Method",
                        "type": "String",
                        "value": "GET",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "method"
                        }
                    },
                    {
                        "label": "URL",
                        "type": "String",
                        "value": "http://dummy.restapiexample.com/api/v1/employee/1",
                        "binding": {
                            "type": "camunda:inputParameter",
                            "name": "url"
                        }
                    },

                    {
                        "label": "Response",
                        "type": "String",
                        "value": "response",
                        "binding": {
                            "type": "camunda:outputParameter",
                            "source": "S(response).prop('data')",
                            "scriptFormat": "JavaScript"
                        }
                    }
                ]
            }
        }
    }
]
1 Like