Get ID of an Task after Process is started


#1

I want to start a process and after the process is started, I want to get the ID of the started Task and save it to a variable so I can use it in a later stage of the process to get the variables from the task.
I’m relatively new to Camunda so I would appreciate every help possible


#2

Hi @Patrick_Unverricht,

do you want to use a REST call or Java code for this?
Have a look into our REST documentation on how to achieve this with a REST call.

If you want to use Java, one possible way would be:
taskService.createTaskQuery().list() to get all currently active tasks. (You can filter them in this query) To get the ID, call task.getId() on a single task object.

However, consider saving the variables you need later on in the process as process variables. This way they will be available in the scope of the process instance. Further reading

Cheers,
Miklas


#3

Hi @Miklas,

My Plan rightnow was to use a GET Call to get all tasks and then access the first element because it would be the last task created and then get the ID of the Object, however i dont know how to access it because technicaly, if im right, the response of GET /task is a JSON object containing multiple other JSON objects. So I would need to know how to get the Key of The first element in the JSON object


#4

You can use camunda-spin for JSON processing. Find more information on Spin in our documentation: https://docs.camunda.org/manual/latest/user-guide/data-formats/

Cheers,
Miklas