0 votes
1.5k views
in Javascript API by

1 Answer

0 votes
by (30.6k points)

The JavaScript API has no "task list for user X" method in one call; combine the search API (task list for a user) with the task objects, or query the current user's tasks:

// server-side script (any 8.5.x / BAW): tasks of a user through the search REST API called with BPMRESTRequest
var req = new BPMRESTRequest();
req.method = "PUT"; req.resource = "/search/query";
req.parameters = { "organization": "byTask", "run": "true", "filterByCurrentUser": "false", "size": "500",
                   "condition": "taskStatus|Received", "condition": "assignedToUser|" + tw.local.userName };   // several conditions: pass as an array in newer releases
var res = tw.system.invokeREST(req);
var rows = JSON.parse(res.content).data.data;                     // taskId, taskSubject, taskDueDate, instanceId, ...
tw.local.tasks = new tw.object.listOf.TaskInfo();
for (var i = 0; i < rows.length; i++) {
  var t = tw.system.findTaskByID(rows[i].taskId);                 // TWTask: subject, status, assignedTo, dueDate, processInstance, priority
  var info = new tw.object.TaskInfo(); info.id = t.id; info.subject = t.subject; info.due = t.dueDate; info.instance = t.processInstance.id;
  tw.local.tasks.insertIntoList(tw.local.tasks.listLength, info);
}

// current user only, pure JS API (no REST): tw.system.user is the caller; the task list of the caller is not exposed either -
// the Process Portal uses the search / task list REST resources; use them.

Client side (a coach for the logged-in user) it is simpler: the search query with filterByCurrentUser=true (question 756). On BAW 21+ the Process REST v2 GET /bpm/user-tasks?states=ready,claimed returns the caller's tasks (administrators can filter other users' tasks with the model / instance filters) - the clean API going forward.

References

Related questions

0 votes
1 answer 762 views
0 votes
1 answer 2.0k views
+1 vote
1 answer 1.8k views
0 votes
1 answer 1.0k views
0 votes
1 answer 2.2k views
0 votes
1 answer 1.7k views
0 votes
1 answer 1.9k views
0 votes
1 answer 2.1k views
0 votes
1 answer 1.9k views
0 votes
1 answer 2.1k views
0 votes
1 answer 2.2k views
asked May 15, 2016 in REST API by BPM Tips Admin (21.5k points)
0 votes
1 answer 3.3k views
asked Oct 21, 2018 in BPD by BPM Tips Admin (21.5k points)

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...