How do we get the next task Id of a User Input Task. This has to be entered in t

How do we get the next task Id of a User Input Task. This has to be entered in the Send Email Smart Service which is triggered before the User Input Task? Is there any such Out Of The Box function?...

OriginalPostID-114894

OriginalPostID-114894

  • Tasks do not have an ID until they are instantiated. You cannot "predict" what the next task ID will be.
  • We want to disable the alerts and then use a Send Email Node before the actual task and provide an actual link to the task rather than just a link to the Tempo Interface. This way when the user clicks on the link, he lands directly on the exact task rather than on a specific tab. How do we achieve this?
  • You can send the email after the task is instantiated (e.g. a paralel flow one that goes to the task to instantiate it, one that goes to a timer to wait for the task to be instantiated).

    The flow that has the timer would then go to a script task that can call a custom function you will have to create (forum.appian.com/.../ProcessExecutionService.html, int, int, int, java.lang.Integer, java.lang.Integer) to get the current tasks for process and based on your business logic get the desired task from that process then pass that information to the Send Email node.
  • Do you have any sample plugin code to this? The return type for the getCurrentTasksForProcess is a ResultPage.I am not sure how to convert a ResultPage into an Integer type to get tasksids as an integer?
  • Sure! Actually for any ResultPage you just need to look at the API Docs to determine what cast you need. Since according to the Java Docs the getCurrentTasksForProcess returns a ResultPage of TaskSummary objects you just need to call its getResults() method and then cast that to an array of TaskSummary

    TaskSummary[] currentTasksForProcess = (TaskSummary[])currentTasksForProcessResultPage.getResults();
  • It seems you missed my last post, the relevant code for you to build your plugin is in there.

    There are no plans on my end to create a plugin to be shared since you need to adapt it to your specific needs.
  • Oh I know what you mean, when I said "sure" I meant that I was going to provide the two lines to explain how you convert a ResultPage into a TaskSummary[], not that I had a built example, sorry for the confusion.
  • I am getting a null pointer exception when I put the following code with the interface implementation of processExecutionService

    Long[] currentTasksForProcess = new Long[100];
    ProcessExecutionService processExecutionService = new ProcessExecutionService() {
                                  
                                  @Override
                                  public void setServiceContext(ServiceContext arg0) {
                                            // TODO Auto-generated method stub
                                            
                                  }
    ResultPage resultPage;
    resultPage = processExecutionService.getCurrentTasksForProcess(processID, com.appiancorp.suiteapi.process.ProcessExecutionService.UNATTENDED_AND_ATTENDED_TASKS, 1, 10, TaskSummary.SORT_BY_ID, Constants.SORT_ORDER_ASCENDING);
                                  currentTasksForProcess = (Long[])resultPage.getResults();

    What could be the root cause of this null pointer exception?

    Is processExecutionService() null or currentTasksForProcess() .

    The error is at line 1787 which is this:-

    resultPage = processExecutionService.getCurrentTasksForProcess(processID, com.appiancorp.suiteapi.process.ProcessExecutionService.UNATTENDED_AND_ATTENDED_TASKS, 1, 10, TaskSummary.SORT_BY_ID, Constants.SORT_ORDER_ASCENDING);
                                  currentTasksForProcess = (Long[])resultPage.getResults();
  • I resolved this error but quick question :-

    You said , you can do --> TaskSummary[] currentTasksForProcess = (TaskSummary[])currentTasksForProcessResultPage.getResults();

    But there is no return type by the type TaskSummary[] and type casting to a Long[] does not work either? Then how do we get the task ids as a array of integers?
  • This line gives you an array of TaskSummaryObjects because getResults() returns an Array of Objects and TaskSummary[] is by inheritance an Array of Objects so the cast is allowed at compilation time and works at runtime

    TaskSummary[] currentTasksForProcess = (TaskSummary[])currentTasksForProcessResultPage.getResults();

    this gives you a list of details for each task. You can then iterate over these objects and get the task ID which can be stored in a Long[] array.

    Here's an example. In the example I'm finally storing all the task IDs within the varaible currentTasksIdsForProcessArray

    ResultPage currentTasksForProcessResultPage = pes.getCurrentTasksForProcess(processId, type, startIndex, batchSize, sortBy, sortOrder);
    TaskSummary[] currentTasksForProcess = (TaskSummary[])currentTasksForProcessResultPage.getResults();
    List<Long> currentTasksIdsForProcessList = new ArrayList<Long>();
    for (TaskSummary taskSummary : currentTasksForProcess) {
    currentTasksIdsForProcessList.add(taskSummary.getId());
    }
    Long[] currentTasksIdsForProcessArray = currentTasksIdsForProcessList.toArray(new Long[0]);



  • This piece of code is giving me an empty array?
    Long[] currentTasksIdsForProcessArray = new Long[100];
                        TaskSummary[] taskResults = new TaskSummary[100];

                        ProcessExecutionService processExecutionService = ServiceLocator.getProcessExecutionService(sc);
                        try {
                        
                                  ResultPage resultPage;
                        
                                  resultPage = processExecutionService.getCurrentTasksForProcess(processID, com.appiancorp.suiteapi.process.ProcessExecutionService.UNATTENDED_AND_ATTENDED_TASKS, 1, 10, TaskSummary.SORT_BY_ID, Constants.SORT_ORDER_ASCENDING);
                                  
                                  taskResults = (TaskSummary[])resultPage.getResults();
                                  List<Long> currentTasksIdsForProcessList = new ArrayList<Long>();
                                  for (TaskSummary taskSummary : taskResults)
                                  {
                                            currentTasksIdsForProcessList.add(taskSummary.getId());
                                  }
                                  System.out.println("Task IDs Array is -->"+currentTasksIdsForProcessList);
                                  currentTasksIdsForProcessArray = currentTasksIdsForProcessList.toArray(new Long[100]);
                                  System.out.println("Task IDs are -->"+currentTasksIdsForProcessArray);
                                  
                        } catch (InvalidProcessException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                        } catch (PrivilegeException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                        }
                        
                        
                        
                        return currentTasksIdsForProcessArray;
  • Ok resolved the error.

    processExecutionService.getCurrentTasksForProcess(processID, com.appiancorp.suiteapi.process.ProcessExecutionService.UNATTENDED_AND_ATTENDED_TASKS, 0, 10, TaskSummary.SORT_BY_ID, Constants.SORT_ORDER_ASCENDING);

    Start Index should have been from 0 and not 1.
  • That's correct, at the API level arrays follow the Java convention of being 0-based indexed arrays. Only in the UI Appian arrays (not Java arrays) will be 1-based

 Discussion posts and replies are publicly visible