Setting and defining map in model directly

I have set a map with some predefined values in the java class… and called the class using a service task

Map<String, String> processVariables = new HashMap<String, String>();
processVariables.put(“varOne”, “Variables are great!”);
execution.setVariable(“exVar”,processVariables);

The variables were available in the process instance successfully.

Is there any way to declare map or other array data type in the model directly

Hey @Anmol_Gupta,

There are no BPMN symbols to declare variables. So having it visible directly in the graphical model is not possible.

But you could use Script (either as a Script Task or as any type of Listener) to declare variables and give them to the process context. You can define the script in the properties panel of the Camunda Modeler and the Script can be stored within the model. Then your script would be visible in the corresponding XML. So it would be directly in your model

Normally we recommend to store the Script externally too. It is easier to maintain. Further the engine creates new versions of your process if the XML changes. This said if you have your Script in the XML you would get a new process version whenever your Script changes. This can be sometimes not intended because the logic of the model stays the same.

I hope this helps
Cheers
Nele

1 Like

Will try the same, thanks for sharing