Get all variables

If I have the following workflow A —> B —> C. C the current task. How can I retrieve the list of all variables from all tasks before C.

Variables are global - so at any point you can ask for all the variables in the process.
are you interested in historic variables?

No, I’m not looking for the variables in the history. I am interested in the list of variables of the previous tasks of the current process instance.
the method getVariables() retrieve only the liste of variables of current task :frowning:

Are you created local variables in the previous tasks?

this an example of my variables I created via a modeler template json.

 <bpmn:serviceTask id="Task_0b410rg" name="env" camunda:modelerTemplate="InitTask" camunda:delegateExpression="#{genericAdapter}">
      <camunda:inputParameter name="Input_idT">valeur 1</camunda:inputParameter>
      <camunda:inputParameter name="Input_app">valeur 1</camunda:inputParameter>
      <camunda:inputParameter name="Input_rd">valeur 2</camunda:inputParameter>

Is there any specific reason why you’re using input parameters?
They’re not required to create variables.

to customize my service task with predefined and prefilled variables. After the end of this service task I can not retrieve the variables

The variables created in this way are not stored in history - if you want to store them you need to explicitly set the variables in your service task

execution.setVariable("someVar", 1);

Yes I did. And if I do getvariables I will get the list of my variables but when I leave this task I can not find it any more.

Can you upload your code please?

public void execute(DelegateExecution execution) {
Map<String, Object> variables = execution.getVariables();	

mail.bpmn (3.6 KB)

Can i also see how you’re setting variables?


public class InjectionVariableService {

private Field getAccessibleField(Class<?> clazz, String fieldName) throws NoSuchFieldException {

	Field field = clazz.getDeclaredField(fieldName);
	return field;

public void injectEnvironmentVariable(Map<String, String> newEnvMap) throws Exception {
	Class<?> processEnvironment = Class.forName("java.lang.ProcessEnvironment");
	Field unmodifiableMapField = getAccessibleField(processEnvironment, "theUnmodifiableEnvironment");
	Object unmodifiableMap = unmodifiableMapField.get(null);
	injectIntoUnmodifiableMap(newEnvMap, unmodifiableMap);

	Field mapField = getAccessibleField(processEnvironment, "theEnvironment");
	((Map<String, String>) mapField.get(null)).putAll(newEnvMap);

@SuppressWarnings({ "unchecked", "rawtypes" })
private void injectIntoUnmodifiableMap(Map<String, String> newEnvMap, Object map)
		throws ReflectiveOperationException {
	Class unmodifiableMap = Class.forName("java.util.Collections$UnmodifiableMap");
	Field field = getAccessibleField(unmodifiableMap, "m");
	Object obj = field.get(map);
	((Map<String, String>) obj).putAll(newEnvMap);


I can’t see where you’re actually setting the variables as part of the instance.

when running the mail init task I used the method below to set the list of variables
public void execute(DelegateExecution execution) {
/* some code to init envVariablesMap */
try {
} catch (Exception e) {



but at the send task I can not get variables.
And attached the modeler template.MailInit_ServiceTask.json (2.0 KB)

Can you confirm this method is actually storing the variables in the DB?

How can I check

Take a look to see if it appears in the ACT_HI_VARINST table. If it doesn’t it means your code needs to be fixed to ensure it stores the variables properly.

The information is persisted in the database at the end of the instance process.