cancel
Showing results for 
Search instead for 
Did you mean: 

Get all userTask formProperty values for all tasks

thevanoman
Champ in-the-making
Champ in-the-making
Hello. I need help. I have a lot of started processes. And in every process i have several tasks like this:

<userTask id="submit" name="Submit vacation request" …>
        <extensionElements>
          …
          <activiti:formProperty id="actions" name="actions" type="enum" variable="action" required="true">
            <activiti:value id="submit" name="Submit request"></activiti:value>
            <activiti:value id="update" name="Update request"></activiti:value>
            <activiti:value id="delete" name="Delete request"></activiti:value>
          </activiti:formProperty>


I need to get all values of formProperty "actions" for every task where some user is assignee or candidate for several processes (maximum 50)

I need something like
    process_instance_id1 :
        -task1:
            -value1  (of formProperty with id = 'actions')
            -value2
        -task2:
            -value1
              …
    process_instance_id2 :
        -task1:
            -value1
            -value2
        -task2:
            -value1
              …

For input i have only ids of processes.
I  know that for one process I can do this:

    List<Task> tasks = createTaskQueryForAssigneeOrCandidate(userId, processInstanceId).list();
    for (Task task: tasks) {
        List<FormProperty> formProperties = formService.getTaskFormData(task.getId()).getFormProperties();
        ….

    private NativeTaskQuery createTaskQueryForAssigneeOrCandidate(final String userId, final String processInstanceId) {
        final StringBuilder query = new StringBuilder();
        query.append("SELECT * FROM ( SELECT DISTINCT ON (TASK.name_) * FROM ");
        query.append(managementService.getTableName(Task.class));
        query.append(" TASK left join ");
        query.append(managementService.getTableName(IdentityLinkEntity.class));
        query.append(" IDENTITY_LINK on IDENTITY_LINK.TASK_ID_ = TASK.ID_");
        query.append(" WHERE (TASK.ASSIGNEE_ = #{userName} OR (IDENTITY_LINK.TYPE_ = 'candidate' and IDENTITY_LINK.USER_ID_ = #                                        {userName})) ");
        query.append("AND TASK.proc_inst_id_ = #{processInstanceId}) result ORDER BY result.priority_ DESC");
        final NativeTaskQuery taskQuery = taskService.createNativeTaskQuery();
        taskQuery.sql(query.toString());
        taskQuery.parameter(USER_PARAMETER_NAME, userId);
        taskQuery.parameter("processInstanceId", processInstanceId);
        return taskQuery;
    }
2 REPLIES 2

balsarori
Champ on-the-rise
Champ on-the-rise
I'm not sure why you want to access the form properties. Or maybe you want to access the submitted value of form property 'actions'.

However, you can also do this

[java]
// Get all tasks of specific process instance where user is assigned to or a candidate
taskService.createTaskQuery().taskCandidateOrAssigned(userId).processInstanceId(myProcessId).list();

// Also, you can get all tasks of process instances of a certain process definition

// Get all tasks of all process instances of a process definition where userId is assigned to or a candidate
taskService.createTaskQuery().taskCandidateOrAssigned(userId).processDefinitionId(myProcessDefId).list();

// Or use processDefinitionKey to filter regardless of process definition version
taskService.createTaskQuery().taskCandidateOrAssigned(userId).processDefinitionKey(myProcessDefKey).list();


// Use taskDefinitionKey to filter tasks by userTask id defined in process definition (i.e.userTask id="submit")
taskService.createTaskQuery().taskCandidateOrAssigned(userId).processDefinitionKey(myProcessDefKey).taskDefinitionKey("submit").list();
[/java]

thevanoman
Champ in-the-making
Champ in-the-making
balsarori , thank you, but I need all values of form property with name "actions" that located inside some userTask. I have a lot of tasks and I need to get it for all of them at once.