cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter /tasks REST API output to show only assigned tasks?

sheriv
Champ in-the-making
Champ in-the-making

Hi,

My first query here. 

I want to retrieve tasks assigned to the logged in user. The initial plan was to use GET /tasks API.

However ,after testing for some scenarios, I understood that the API returns tasks if the logged in user is the creator of the process too.

API documentation(on API-Explorer) is not clear on this. 

"Gets a list of tasks visible to the authenticated user.

Tasks are returned for which the authenticated user is the assignee or
a candidate...."

My query is how do i filter the response to retrieve only the assigned or candidate tasks? ( i.e. to avoid the  unassigned tasks from the processes created by logged in user)

Thank you,

Viresh

P.S.: I usually find answers on this forum or via code on github but for this query couldn't find enough info. 

Edit 1:

My quick fix idea ,as of now, is to use GET /tasks/{taskId}/candidates  API respone to check if the logged in user is one of the candidates.   As the current scenarios ,doesn't invlove groups, this should be sufficient. 

But was wondering if there's a better way. Also wonder if the API documentation is incomplete ,if not incorrect.

Thank you.

4 REPLIES 4

angelborroy
Community Manager Community Manager
Community Manager

Not sure if I understand your question...

I created a workflow with "admin" user and assigned a task to "test" user.

When executing following invocation from with user "test" authenticated...

curl -X GET "http://127.0.0.1:8080/alfresco/api/-default-/public/workflow/versions/1/tasks" -H  "accept: application/json"

... I'm getting this result.

"entries": [
      {
        "entry": {
          "processDefinitionId": "activitiAdhoc:1:4",
          "processId": "167",
          "name": "Adhoc Task",
          "description": "Adhoc Task",
          "startedAt": "2022-02-01T16:37:21.504+0000",
          "id": "213",
          "assignee": "test",
          "state": "claimed",
          "activityDefinitionId": "adhocTask",
          "priority": 2,
          "formResourceKey": "wf:adhocTask"
        }
      }
    ]

That seems expected to me.

What should be the response of this request?

Hyland Developer Evangelist

sheriv
Champ in-the-making
Champ in-the-making

hi angelborroy,

Thank you for the quick response.

It's my mistake that i did not describe the scenario completely.

I have created a custom workflow by following jeffpotts's tutorial. 

for simplicity let's say the workflow has 4 tasks assigned to testuser1 to 4  respectively i.e.

task1-->candidateusers: testuser1

task2-->candidateusers: testuser2

task3-->candidateusers: testuser3

task4-->candidateusers: testuser4

Note: i am using activiti:candidateusers to make the tasks pooled one. 

Now ,coming to my issue, the scenario is as below.

testuser4  creates the process.

testuser1 being candidate for task1 is a potential candiate.

My expected API response in this case is 

for testuser1:  response should have  task1 entry.

for testuser4: response should not have any entry.

current API behavior:

for testuser1:  response  has  task1 entry.

for testuser4: response has task1 entry.

I presume testuser4 being the creator of the process is able to view task1 entry even though he/she is not assigned with that task neither is he/she a candidate user.

But for me, if i have to show list of assigned tasks,  i should know if the task entry in response is because it's assigned to me or because i was the process creator.

My query was how to differentiate the task entries in the response along this?

Hope this helps in simplification of my query.

Thank you,

Viresh

You may try filtering by assignee (user "test" in the following sample):

http://127.0.0.1:8080/alfresco/api/-default-/public/workflow/versions/1/tasks?where=(assignee%3Dtest)
Hyland Developer Evangelist

sheriv
Champ in-the-making
Champ in-the-making

Hi,

I tried the api with whee clause in api-explorer.

I think the assignee is not set in the response entry if the task is a pooled one. And thus /tasks will not return the pooled tasks in the return if i use where clause.

Following are the responses for test user "tu1":

Without where clause:

curl -X GET "http://<ip>:8080/alfresco/api/-default-/public/workflow/versions/1/tasks" -H "accept: application/json" -H "authorization: Basic dHUxOnR1MQ=="

response:

{
  "list": {
    "pagination": {
      "count": 4,
      "hasMoreItems": false,
      "totalItems": 4,
      "skipCount": 0,
      "maxItems": 100
    },
    "entries": [
      {
        "entry": {
          "processDefinitionId": "myWF:24:5308",
          "processId": "5757",
          "name": "myReview1",
          "description": "myReview1",
          "startedAt": "2022-02-01T13:10:07.969+0000",
          "id": "5933",
          "state": "unclaimed",
          "activityDefinitionId": "usertask5",
          "priority": 2,
          "formResourceKey": "mywf:myReview1Task"
        }
      },
      {
        "entry": {
          "processDefinitionId": "mywf:24:5308",
          "processId": "5965",
          "name": "myReview1",
          "description": "TEST tu2 assignments",
          "startedAt": "2022-02-01T13:19:28.653+0000",
          "id": "6044",
          "state": "unclaimed",
          "activityDefinitionId": "usertask3",
          "priority": 2,
          "formResourceKey": "mywf:myReview1Task"
        }
      },
      {
        "entry": {
          "processDefinitionId": "mywf:24:5308",
          "processId": "6575",
          "name": "myReview1",
          "description": "myReview1",
          "startedAt": "2022-02-02T11:37:35.027+0000",
          "id": "6652",
          "state": "unclaimed",
          "activityDefinitionId": "usertask3",
          "priority": 2,
          "formResourceKey": "mywf:myReview1Task"
        }
      },
      {
        "entry": {
          "processDefinitionId": "mywf:24:5308",
          "processId": "6695",
          "name": "myReview1",
          "description": "myReview1",
          "startedAt": "2022-02-02T11:39:26.222+0000",
          "id": "6772",
          "state": "unclaimed",
          "activityDefinitionId": "usertask3",
          "priority": 2,
          "formResourceKey": "mywf:myReview1Task"
        }
      }
    ]
  }
}

with where clause:

curl -X GET "http://<ip>:8080/alfresco/api/-default-/public/workflow/versions/1/tasks?where=(assignee%3Dtu1)" -H  "accept: application/json" -H  "authorization: Basic dHUxOnR1MQ=="

response:

{
  "list": {
    "pagination": {
      "count": 0,
      "hasMoreItems": false,
      "totalItems": 0,
      "skipCount": 0,
      "maxItems": 100
    },
    "entries": []
  }
}

My updated quick fix is as below:

get all the pooled tasks:  filter it by using  response of /tasks/<taskId>/candidates.  -->this will cover cases where the bpmn task assignment is done via  activiti:candidateusers.

get all the assigned tasks: using where clause for assignee ------->this will be useful for tasks where assignment is direct such as {initiator.user.name}

Please let me know if there's a better way to handle this. 

Also it would be very much helpful for me if you could point me to github source location which shows how shareUI does it for "My tasks" listing.

(i did search for it but as I am relatively new with alfresco, couldn't find the exact source and/or ftl file for tasks listing)

thank you.

viresh