I am trying to get the active tasks of an instance using the below code. There i

I am trying to get the active tasks of an instance using the below code. There is an active task at a process which is nested two levels from the parent process. And the below code is not capturing the active task that I am looking for. How can I get the tasks of a subprocess?

TaskSummary[] tss = (TaskSummary[]) pes.getCurrentTasksForProcess(
                                                  cddProcessId,
                                                  ProcessExecutionService.UNATTENDED_AND_ATTENDED_TASKS, 0,
                                                  Constants.COUNT_ALL, TaskSummary.SORT_BY_ASSIGNED_TIME,
                                                  Constants.SORT_ORDER_DESCENDING).getResults();

OriginalPostID-198760

OriginalPostID-198760

  Discussion posts and replies are publicly visible

Parents
  • Hi karthikeyans75,

    You should have a look at the Task Smart Service plugin. It has function that returns the active tasks for a process; you can pass the parent process id and a boolean parameter that determines whether the function should look at child processes. Here is the relevant code:

    @Function
              public Long[] getActiveTaskIDsForProcess(ProcessExecutionService pes, @Parameter Long processID,
                                  @Parameter(required = false) Boolean includeSubs) {
                        if (includeSubs == null) {
                                  includeSubs = false;
                        }
                        Long[] idArray = new Long[0];
                        try {
                                  ResultPage rp1 = pes.getTasksWithStatusForProcess(processID,
                                                      TaskSummary.TASK_STATUS_ASSIGNED, includeSubs, 0, Constants.COUNT_ALL,
                                                      TaskSummary.SORT_BY_ASSIGNED_TIME, Constants.SORT_ORDER_ASCENDING);
                                  ResultPage rp2 = pes.getTasksWithStatusForProcess(processID,
                                                      TaskSummary.TASK_STATUS_ACCEPTED, includeSubs, 0, Constants.COUNT_ALL,
                                                      TaskSummary.SORT_BY_ASSIGNED_TIME, Constants.SORT_ORDER_ASCENDING);
                                  idArray = new Long[rp1.getNumResults() + rp2.getNumResults()];
                                  TaskSummary[] ts1 = (TaskSummary[]) rp1.getResults();
                                  TaskSummary[] ts2 = (TaskSummary[]) rp2.getResults();

                                  for (int i = 0; i < ts1.length; i++) {
                                            idArray[i] = ts1[i].getId();
                                  }
                                  for (int i = 0; i < ts2.length; i++) {
                                            idArray[i + ts1.length] = ts2[i].getId();
                                  }
                        } catch (Exception e) {
                                  LOG.error(e, e);
                        }
                        return idArray;
              }

Reply
  • Hi karthikeyans75,

    You should have a look at the Task Smart Service plugin. It has function that returns the active tasks for a process; you can pass the parent process id and a boolean parameter that determines whether the function should look at child processes. Here is the relevant code:

    @Function
              public Long[] getActiveTaskIDsForProcess(ProcessExecutionService pes, @Parameter Long processID,
                                  @Parameter(required = false) Boolean includeSubs) {
                        if (includeSubs == null) {
                                  includeSubs = false;
                        }
                        Long[] idArray = new Long[0];
                        try {
                                  ResultPage rp1 = pes.getTasksWithStatusForProcess(processID,
                                                      TaskSummary.TASK_STATUS_ASSIGNED, includeSubs, 0, Constants.COUNT_ALL,
                                                      TaskSummary.SORT_BY_ASSIGNED_TIME, Constants.SORT_ORDER_ASCENDING);
                                  ResultPage rp2 = pes.getTasksWithStatusForProcess(processID,
                                                      TaskSummary.TASK_STATUS_ACCEPTED, includeSubs, 0, Constants.COUNT_ALL,
                                                      TaskSummary.SORT_BY_ASSIGNED_TIME, Constants.SORT_ORDER_ASCENDING);
                                  idArray = new Long[rp1.getNumResults() + rp2.getNumResults()];
                                  TaskSummary[] ts1 = (TaskSummary[]) rp1.getResults();
                                  TaskSummary[] ts2 = (TaskSummary[]) rp2.getResults();

                                  for (int i = 0; i < ts1.length; i++) {
                                            idArray[i] = ts1[i].getId();
                                  }
                                  for (int i = 0; i < ts2.length; i++) {
                                            idArray[i + ts1.length] = ts2[i].getId();
                                  }
                        } catch (Exception e) {
                                  LOG.error(e, e);
                        }
                        return idArray;
              }

Children
No Data