Unable to get Variable Instances(History) using TaskId

im using Camunda Rest Api to retrive history of Variable Instances with respect to taskId but getting response null (Empty array from API)

http://localhost:8080/engine-rest/history/variable-instance (POST)

body:
{
“taskIdIn”: [“12f9b1f2-cead-11eb-ba6d-7e7e370e48be”]
}

and i went though the database tables i have found TaskId column value itself is NULL.

SELECT * FROM camundadb.act_hi_varinst;

Requirement:

i want to get the history of Form Variables for particular taskId …can anyone please suggest how to get it.

It means the variable is not in the scope of task level. Try searching by process instance id.

Yup Aravindhrs, But im not able to get exact Variables instances for particular task if im searching with processInstanceId(im getting all variableInstances for whole Process).can you please suggest us

@aredd119 Read about the variable scopes and visibility in here: Process Variables | docs.camunda.org

You will get variables only if you set like below, meaning that setting in local scope. “Local” means the variable is always set on the task that is provided by “taskId”. Not in any of the higher scopes. You can only use this method for tasks, not for executions.


@Component
public class SetTaskLocalVariablesListener implements TaskListener {

	@Override
	public void notify(DelegateTask delegateTask) {
		VariableMap variableMap = Variables.createVariables().putValue("chapters", 10).putValue("examples", 100);
		delegateTask.setVariablesLocal(variableMap);
	}

}


Deploy this bpmn file and test: readEBook.bpmn (4.1 KB)

Read more about variable scopes: https://groups.google.com/g/camunda-bpm-users/c/KvrClQpB05k

Thank you so much @aravindhrs

@aravindhrs here i have decoupled engine and Client, So from Client im calling Engine API’s for start or submit tasks ,how can achieve delegates calling,

please suggest

Delegates should be in the classpath where engine resides. Delegates are not for invoking via rest api. It’s part of the execution flow itself, engine takes care of executing the delegates attached to the activity.

Passing variables via Complete task rest api will be set to execution scope which is same as:

runtimeService.setVariable(delegateTask.getExecutionId(), "variableName", value);

To set variables to local scope at the task use this api: