Problem Statement :
You want to get details about a task. You know the task id and you would like to fetch details like who is holding the task, who assigned this task, if its open or closed, the task subject, priority etc.
Solution :
Use the following code. You need to have an input variable as tw.local.taskId (String) that has the task-id and an output variable of type BPM_Task. BPM_Task has the following simple variables in it:
You want to get details about a task. You know the task id and you would like to fetch details like who is holding the task, who assigned this task, if its open or closed, the task subject, priority etc.
Solution :
Use the following code. You need to have an input variable as tw.local.taskId (String) that has the task-id and an output variable of type BPM_Task. BPM_Task has the following simple variables in it:
- taskId (String)
- assignedUser (String)
- receivedFromUser (String)
- closedByUser (String)
- assignedGroup (String)
- status (String)
- subject (String)
- priority (String)
- receivedDate (Date)
- receivedDateString (String)
- dueDate (Date)
- dueDateString (String)
- readDate (Date)
- readDateString (String)
- closeDate (Date)
- closeDateString (String)
- instanceId (String)
var twSearch = new TWSearch();
var taskId = new TWSearchColumn();
taskId.type = TWSearchColumn.Types.Task;
taskId.name = TWSearchColumn.TaskColumns.ID;
var taskAssignedToUser = new TWSearchColumn();
taskAssignedToUser.type = TWSearchColumn.Types.Task;
taskAssignedToUser.name = TWSearchColumn.TaskColumns.AssignedToUser;
var taskReceivedFromUser = new TWSearchColumn();
taskReceivedFromUser.type = TWSearchColumn.Types.Task;
taskReceivedFromUser.name = TWSearchColumn.TaskColumns.ReceivedFrom;
var taskClosedByUser = new TWSearchColumn();
taskClosedByUser.type = TWSearchColumn.Types.Task;
taskClosedByUser.name = TWSearchColumn.TaskColumns.ClosedBy;
var taskAssignedToRole = new TWSearchColumn();
taskAssignedToRole.type = TWSearchColumn.Types.Task;
taskAssignedToRole.name = TWSearchColumn.TaskColumns.AssignedToRole;
var taskStatus = new TWSearchColumn();
taskStatus.type = TWSearchColumn.Types.Task;
taskStatus.name = TWSearchColumn.TaskColumns.Status;
var taskSubject = new TWSearchColumn();
taskSubject.type = TWSearchColumn.Types.Task;
taskSubject.name = TWSearchColumn.TaskColumns.Subject;
var taskPriority = new TWSearchColumn();
taskPriority.type = TWSearchColumn.Types.Task;
taskPriority.name = TWSearchColumn.TaskColumns.Priority;
var taskReceivedDate = new TWSearchColumn();
taskReceivedDate.type = TWSearchColumn.Types.Task;
taskReceivedDate.name = TWSearchColumn.TaskColumns.ReceivedDate;
var taskDueDate = new TWSearchColumn();
taskDueDate.type = TWSearchColumn.Types.Task;
taskDueDate.name = TWSearchColumn.TaskColumns.DueDate;
var taskReadDate = new TWSearchColumn();
taskReadDate.type = TWSearchColumn.Types.Task;
taskReadDate.name = TWSearchColumn.TaskColumns.ReadDate;
var taskCloseDate = new TWSearchColumn();
taskCloseDate.type = TWSearchColumn.Types.Task;
taskCloseDate.name = TWSearchColumn.TaskColumns.ClosedDate;
var instanceId = new TWSearchColumn();
instanceId.type = TWSearchColumn.Types.ProcessInstance;
instanceId.name = TWSearchColumn.ProcessInstanceColumns.ID;
twSearch.columns = new Array(taskId, taskAssignedToUser, taskReceivedFromUser, taskClosedByUser, taskAssignedToRole, taskStatus, taskSubject, taskPriority, taskReceivedDate, taskDueDate, taskReadDate, taskCloseDate, instanceId);
var searchCondition = new TWSearchCondition();
searchCondition.column = taskId;
searchCondition.operator = TWSearchCondition.Operations.Equals;
searchCondition.value = tw.local.taskId;
twSearch.conditions = new Array(searchCondition);
twSearch.organizedBy = TWSearch.OrganizeByTypes.Task;
var results = twSearch.execute();
if(results && results.rows && results.rows.length == 1) {
var row = results.rows[0];
tw.local.taskDetails = new tw.object.BPM_Task();
tw.local.taskDetails.taskId = row.values[0].toString();
tw.local.taskDetails.assignedUser = row.values[1]?row.values[1].toString():null;
tw.local.taskDetails.receivedFromUser = row.values[2]?row.values[2].toString():null;
tw.local.taskDetails.closedByUser = row.values[3]?row.values[3].toString():null;
tw.local.taskDetails.assignedGroup = row.values[4]?row.values[4].toString():null;
tw.local.taskDetails.status = row.values[5]?row.values[5].toString():null;
tw.local.taskDetails.subject = row.values[6]?row.values[6].toString():null;
tw.local.taskDetails.priority = row.values[7]?row.values[7].toString():null;
tw.local.taskDetails.receivedDate = row.values[8]?row.values[8]:null;
tw.local.taskDetails.receivedDateString = tw.local.taskDetails.receivedDate?tw.local.taskDetails.receivedDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.dueDate = row.values[9]?row.values[9]:null;
tw.local.taskDetails.dueDateString = tw.local.taskDetails.dueDate?tw.local.taskDetails.dueDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.readDate = row.values[10]?row.values[10]:null;
tw.local.taskDetails.readDateString = tw.local.taskDetails.readDate?tw.local.taskDetails.readDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.closeDate = row.values[11]?row.values[11]:null;
tw.local.taskDetails.closeDateString = tw.local.taskDetails.closeDate?tw.local.taskDetails.closeDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.instanceId = row.values[12]?row.values[12].toString():null;
}
var taskId = new TWSearchColumn();
taskId.type = TWSearchColumn.Types.Task;
taskId.name = TWSearchColumn.TaskColumns.ID;
var taskAssignedToUser = new TWSearchColumn();
taskAssignedToUser.type = TWSearchColumn.Types.Task;
taskAssignedToUser.name = TWSearchColumn.TaskColumns.AssignedToUser;
var taskReceivedFromUser = new TWSearchColumn();
taskReceivedFromUser.type = TWSearchColumn.Types.Task;
taskReceivedFromUser.name = TWSearchColumn.TaskColumns.ReceivedFrom;
var taskClosedByUser = new TWSearchColumn();
taskClosedByUser.type = TWSearchColumn.Types.Task;
taskClosedByUser.name = TWSearchColumn.TaskColumns.ClosedBy;
var taskAssignedToRole = new TWSearchColumn();
taskAssignedToRole.type = TWSearchColumn.Types.Task;
taskAssignedToRole.name = TWSearchColumn.TaskColumns.AssignedToRole;
var taskStatus = new TWSearchColumn();
taskStatus.type = TWSearchColumn.Types.Task;
taskStatus.name = TWSearchColumn.TaskColumns.Status;
var taskSubject = new TWSearchColumn();
taskSubject.type = TWSearchColumn.Types.Task;
taskSubject.name = TWSearchColumn.TaskColumns.Subject;
var taskPriority = new TWSearchColumn();
taskPriority.type = TWSearchColumn.Types.Task;
taskPriority.name = TWSearchColumn.TaskColumns.Priority;
var taskReceivedDate = new TWSearchColumn();
taskReceivedDate.type = TWSearchColumn.Types.Task;
taskReceivedDate.name = TWSearchColumn.TaskColumns.ReceivedDate;
var taskDueDate = new TWSearchColumn();
taskDueDate.type = TWSearchColumn.Types.Task;
taskDueDate.name = TWSearchColumn.TaskColumns.DueDate;
var taskReadDate = new TWSearchColumn();
taskReadDate.type = TWSearchColumn.Types.Task;
taskReadDate.name = TWSearchColumn.TaskColumns.ReadDate;
var taskCloseDate = new TWSearchColumn();
taskCloseDate.type = TWSearchColumn.Types.Task;
taskCloseDate.name = TWSearchColumn.TaskColumns.ClosedDate;
var instanceId = new TWSearchColumn();
instanceId.type = TWSearchColumn.Types.ProcessInstance;
instanceId.name = TWSearchColumn.ProcessInstanceColumns.ID;
twSearch.columns = new Array(taskId, taskAssignedToUser, taskReceivedFromUser, taskClosedByUser, taskAssignedToRole, taskStatus, taskSubject, taskPriority, taskReceivedDate, taskDueDate, taskReadDate, taskCloseDate, instanceId);
var searchCondition = new TWSearchCondition();
searchCondition.column = taskId;
searchCondition.operator = TWSearchCondition.Operations.Equals;
searchCondition.value = tw.local.taskId;
twSearch.conditions = new Array(searchCondition);
twSearch.organizedBy = TWSearch.OrganizeByTypes.Task;
var results = twSearch.execute();
if(results && results.rows && results.rows.length == 1) {
var row = results.rows[0];
tw.local.taskDetails = new tw.object.BPM_Task();
tw.local.taskDetails.taskId = row.values[0].toString();
tw.local.taskDetails.assignedUser = row.values[1]?row.values[1].toString():null;
tw.local.taskDetails.receivedFromUser = row.values[2]?row.values[2].toString():null;
tw.local.taskDetails.closedByUser = row.values[3]?row.values[3].toString():null;
tw.local.taskDetails.assignedGroup = row.values[4]?row.values[4].toString():null;
tw.local.taskDetails.status = row.values[5]?row.values[5].toString():null;
tw.local.taskDetails.subject = row.values[6]?row.values[6].toString():null;
tw.local.taskDetails.priority = row.values[7]?row.values[7].toString():null;
tw.local.taskDetails.receivedDate = row.values[8]?row.values[8]:null;
tw.local.taskDetails.receivedDateString = tw.local.taskDetails.receivedDate?tw.local.taskDetails.receivedDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.dueDate = row.values[9]?row.values[9]:null;
tw.local.taskDetails.dueDateString = tw.local.taskDetails.dueDate?tw.local.taskDetails.dueDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.readDate = row.values[10]?row.values[10]:null;
tw.local.taskDetails.readDateString = tw.local.taskDetails.readDate?tw.local.taskDetails.readDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.closeDate = row.values[11]?row.values[11]:null;
tw.local.taskDetails.closeDateString = tw.local.taskDetails.closeDate?tw.local.taskDetails.closeDate.format('MM/dd/yy hh:mm:ss aaa'):null;
tw.local.taskDetails.instanceId = row.values[12]?row.values[12].toString():null;
}