Askar Kalykov
Askar Kalykov

Reputation: 2591

Easy way to get task name by task definition id

There is a comparatively easy way to get process definition name by key, but I can't find any way (except to just parse BPMNModel) to get task definition name by task definition id (and, for example, process definition id). Does anyone know about something similar?

EDIT

I know that I can get task name by task instance (that is, org.camunda.bpm.engine.task.Task#getName), but I need to get task name by task definition (that is, I have no instances of org.camunda.bpm.engine.task.Task).

Upvotes: 0

Views: 4207

Answers (1)

Martin Schimak
Martin Schimak

Reputation: 1373

With the TaskService you can create a query for tasks by calling its method createTaskQuery(). The created task query object then offers several methods to narrow down the query by passing query parameters, e.g.

  • processDefinitionId("") => the id of the process definition deployment the task belongs to
  • processDefinitionKey("") => the id of the process definition in the bpmn xml
  • taskDefinitionKey("") => the id of the task itself in the bpmn xml

The query then returns either a list() of Task objects or a singleResult() Task. And the Task interface has a method getName():

Task task = taskService.createTaskQuery().taskDefinitionKey("myKey").singleResult();
String name = task.getName();

Upvotes: 2

Related Questions