Define Transient Variables in BPMN?

When configuring a custom Service-Task i prefer to use camunda’s Input / Output Parameters. I realized, that in most cases i don’t really need the Input-Parameters to be persisted. Is it possible to declare (within my BPMN) that certain Input-Parameters shall be transient ones?

I know that i can use Field-Injections instead, but than i end up spreading the required Servie-Task-Inputs as Field-Injections (if no persistence is needed) and Input-Parameters (if persistence is required).

I don’t think this is possible. input and out parameters will always create a regular variable. There isn’t any way i know of that you could make it transient.

@sreiser you can implement the following as Start Listeners or Task Listeners:

Listener: Script: javascript

var Variables = Java.type('org.camunda.bpm.engine.variable.Variables')
var myStringVar = Variables.stringValue("myValue", true)
execution.setVariableLocal("theTransientVariableName", myStringVar)

Should be able to one line it with something like:

execution.setVariableLocal('theVariableName', Java.type('org.camunda.bpm.engine.variable.Variables').stringValue("myValue", true))

see Variables (Camunda BPM Javadocs 7.14.6-ee) for other methods available other than stringValue(...)

1 Like

It would prob be a good feature request for Camunda to expose the Variables class in the EL Resolver so expressions can access the org.camunda.bpm.engine.variable.Variables static methods

1 Like

@StephenOTT thanks, your suggestion worked for us while not using Modeler-Templates.

Now as we started to define custom Modeler-Templates for our Service-Tasks we ran into the next issue unfortunately.
It seems like your suggested approach doesn’t go well with the template rules, since camunda:executionListener only accepts the property type Hidden so it cannot have user input.

We also tried to use camunda:executionListener to create the transient variable first and camunda:inputParameter to set it’s value, but this fails with:

org.camunda.bpm.engine.ProcessEngineException: ENGINE-17006 Cannot set transient variable with name my_transient_var to non-transient variable and vice versa.

Template Example
{
    "name": "Transient Vars Test",
    "id": "org.example.TransientVarsTest",
    "version": 1,
    "appliesTo": [
        "bpmn:ServiceTask"
    ],
    "properties": [
        {
            "type": "Hidden",
            "value": "execution.setVariableLocal('my_transient_var', Java.type('org.camunda.bpm.engine.variable.Variables').stringValue('myValue', true))",
            "binding": {
                "type": "camunda:executionListener",
                "event": "start",
                "scriptFormat": "javascript"
            }
        },
        {
            "label": "Your transient value",
            "type": "String",
            "value": "default value",
            "binding": {
                "type": "camunda:inputParameter",
                "name": "my_transient_var"
            },
            "constraints": {
                "notEmpty": true
            }
        },
        {
            "label": "Implementation Class",
            "type": "Hidden",
            "value": "org.example.TransientVarsTest",
            "editable": false,
            "binding": {
                "type": "property",
                "name": "camunda:class"
            }
        }
    ]
}

What are you trying to do with your element template?

Can you provide more detail on your usage.

We’ve implemented a custom Service-Task which validates certain files. Our Validator can be equipped with several parameters that can affect the validation process. We want to expose those parameters to be configurable inside Camunda’s Modeler in a user-friendly manner. Hence the template.

We don’t want to persist the parameters and that’s why we were looking into transient variables.

So basically we want Template-Properties to be only available to the JavaDelegate so that we don’t clutter the Database with unnecessary variables.