Howto get CamundaProperties from extensions of current UserTask

1,181 views
Skip to first unread message

Torsten Geise

unread,
Jul 31, 2015, 6:57:09 AM7/31/15
to camunda BPM users
Dear all,

I want to get the CamundaProperties defined at a Usertask in the Camunda Modeler when the process instance is waiting at this user task. How to achieve this?

Here's the XML-Snippet:

    <bpmn2:userTask id="UserTask_1" name="Usertask 1">
      <bpmn2:extensionElements>
        <camunda:properties>
          <camunda:property value="erledigen,weiterleiten,erledigenMitFolgetask" name="tl-actions"/>
        </camunda:properties>
      </bpmn2:extensionElements>
      <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
    </bpmn2:userTask>

I know that I could find all Usertasks by the following snippet, but is there a shorter way operating on the TaskInstance to avoid iterating through all UserTasks?

BpmnModelInstance bpmnModelInstance = repositoryService().getBpmnModelInstance(processDefinition.getId());
List<String> tlActions = new ArrayList<String>();
Collection<UserTask> userTasks = bpmnModelInstance.getModelElementsByType(UserTask.class);
for (UserTask userTask : userTasks) {
if ("UserTask_1".equals(userTask.getId())) {
CamundaProperties camundaProperties = userTask.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class).singleResult();
for (CamundaProperty camundaProperty : camundaProperties.getCamundaProperties()) {
if ("tl_actions".equals(camundaProperty.getCamundaName())) {
for (String s : camundaProperty.getCamundaValue().split(",")) {
tlActions.add(s.trim());
}
}
}
}
}



Thanks,
Torsten

Sebastian Menski

unread,
Jul 31, 2015, 7:05:33 AM7/31/15
to camunda BPM users, torste...@googlemail.com
Hi Torsten,

you can access the current user task from a task listener [1].

Cheers,
Sebastian

Torsten Geise

unread,
Jul 31, 2015, 9:27:39 AM7/31/15
to camunda BPM users, torste...@googlemail.com, sebastia...@camunda.com
Hi Sebastion,

I need to access the BPMN extension elements before I return the task to a task list in order to send some configuration to the task list. IMHO, a task listener doesn't help at this point.

This shall work in the following context:
- User requests a task list
- Our custom task service performs a task query by utilizing the camunda Java API (TaskQuery)
- For each task load the task variables
- For each task load the camunda properties
- Return custom Task as DTO to the user

Thanks,
Torsten

 

Sebastian Menski

unread,
Jul 31, 2015, 1:17:52 PM7/31/15
to camunda BPM users, torste...@googlemail.com, sebastia...@camunda.com
Hi Torsten,

if you already queried the tasks you can use the key to get the task directly from the model API.

UserTask userTask = modelInstance.getModelElementById(task.getKey());

Cheers,
Sebastian

Torsten Geise

unread,
Aug 3, 2015, 2:36:38 AM8/3/15
to camunda BPM users, torste...@googlemail.com, sebastia...@camunda.com
That works.

Thanks,
Torsten
Reply all
Reply to author
Forward
0 new messages