Hi all,
I’m trying to programatically get a list of all tasks of type ‘userTask’ for a given deployment or process definition. I need this to fill a select-box with all userTasks possible for a given deployment.
Is it possible when none of the tasks are ever executed before? (so history/runtime tables are empty)
I tried searching for a similar answer in the google group and here but no success.
Kind regards,
Nico
Hi @nvanbelle,
You could use the camunda-bpmn-model-api
to retrieve the user tasks for a process definition. Therefore you can use Re pository#getBpmnModelInstance()
and then you could filter for user tasks. This could look like this:
BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance("a-process-definition-id");
Collection<UserTask> userTasks = modelInstance.getModelElementsByType(UserTask.class);
Does it help you?
Cheers,
Roman
4 Likes
Hello @roman.smirnov,
This was exactly what I needed. Thank you!
try {
ProcessDefinition latestActiveProcess = repositoryService
.createProcessDefinitionQuery()
.processDefinitionKey("productOrderProcess")
.latestVersion()
.active()
.singleResult();
BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance(latestActiveProcess.getId());
if (modelInstance != null) {
Collection<UserTask> userTasks = modelInstance.getModelElementsByType(UserTask.class);
result = userTasks
.stream()
.map(t -> new OptionSelectDto(t.getId(), t.getName()))
.collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(OptionSelectDto::getValue))));
}
} catch (Exception e) { ... }