Modeler input/output variables not working as expected?

Hello everyone,

short summary: I want to document service tasks by annotating which input variables they get and which output variables they set (by name) - so that you don’t have to lookup the variable names in the code. I tried to use camunda modeler Input/Output parameters. It doesn’t work.

What I tried to do:
I have a working bpmn process, where the code in a service task sets a variable to a list of objects. This list is later used as a collection of a subprocess. Inside the subprocess another service tasks uses the variable of the collection.

When I add an output parameter to the service tasks which sets the list of objects to a variable, the list is empty at runtime. (When I remove the output parameter declaration everything is back to normal.). So obviously I declare an empty list after my service task has added elements to this list, which overrides all existing values.

When trying to set an input parameter I run into the same problem. Furthermore I can only set text or expressions, but no object from another task.

My questions:
So am I using the Input/Output parameters for the wrong purpose? How can I document variable names and types in the bpmn instead (in the camunda modeler)?

Thank you for your help.

Can you show us your model or how specifically you’ve implemented the input/output variables?

I added the output parameter using the Input/Output tab in the camunda modeler:

Here is the whole file:
regular_income.bpmn (7.0 KB)

And the component that sets the variable:

@Component
public class SelectAllActiveCharactersTask implements JavaDelegate {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        logger.info("select all active characters tasks");

        execution.setVariable("activeCharacters", Arrays.asList("alfons", "bernd", "christian"));
    }
}

For your output paramaters instead of selecting the type “list” use “text” and then in the field put an expression that will populate the variable you’re going to use for your multi-instance subprocess.

Something like this should do the trick:

1 Like

Hi Niall,

thanks, that worked pretty well. I even went a step further and mapped the variable on itself. In my case, that worked either. I don’t know if there are any drawbacks in other cases.

There isn’t really any draw back. in fact it’s not really indented for the use case that you’ve implemented it for. (not that it matters too much :slight_smile: )

The input/ouput feature is intended for cases in which you have a java class that is reused across many processes. Let say the java class asked for the variable “name” every time. but in some processes the variable created is called “firstName” or “fullName”.

The idea would be that you can map the variables to one that the java class is expecting.

1 Like