Getting the list of Notifications inbox items

lir

28-03-2019

Hi,

I need to programmatically pull the list of AEM inbox notifications of a user, with the purpose of sending them a reminder (via email) of the workflow steps waiting for them to take action on.

Can someone please send some hints, or sample code on how to get the list of inbox items.

Thank you

Replies

Highlighted

vaibhavs7024655

28-03-2019

lir  Yes, there are rest endpoints exposed via which you can retrieve the inbox items in a user's inbox. One example of such request is : http://host:port/bin/workflow/inbox which will list all the work items in the inbox of the user.

For more details on using this endpoint further please refer Interacting with Workflows Programmatically  .

Once you have the work items, you can use the InboxItem API "The Adobe AEM Quickstart and Web Application."  to retrieve further details regarding that InboxItem object.

Highlighted

lir

28-03-2019

My code is an OSGI bundle service.

I got a reference to a user instance, and I need to pull the items in this user's inbox.

Highlighted

vaibhavs7024655

28-03-2019

Yeah, so you can use that user's session to authenticate and hit the endpoint /bin/workflow/inbox to retrieve items in that user's inbox. The user will be identified by the HTTP Authentication headers that you will send with the request.

Highlighted

Arun_Patidar

MVP

28-03-2019

Hi,

Can you try below methods to get task and workflow item in osgi code.

ResourceResolver resolver = request.getResourceResolver();

  TaskManager taskManager = resolver.adaptTo(TaskManager.class);

  Iterator<Task> ti = taskManager.getTasks(new Filter());

  WorkflowSession graniteWorkflowSession = resolver.adaptTo(WorkflowSession.class);   

  WorkItem[] workItems = graniteWorkflowSession.getActiveWorkItems();

example servlet aem63app-repo/GetInbox.java at master · arunpatidar02/aem63app-repo · GitHub

Highlighted

lir

02-04-2019

Hi guys,

I am interested on the InboxItem-s (WorkItem-s) that belong to each and every user (who participates in a number of workflows), so I don't see how the suggestion above can help.

My final goal is that once a day, each and every user receive a reminder email, that lists all the pages/assets/etc they are expected to approve/disapprove in AEM.

So my code has to either:

1- impersonate each and every user, one by one, read their InboxItem-s and go from there.
This I think is straightforward, but seams impossible because "A system user cannot impersonate a non system AEM user"

2- access all active workflow instances, and somehow extract what each and every user is expected to approve/disapprove.

I don't know how to approach this code wise.

I hope this is clear and someone can help.

Thank you!

Highlighted

shunnar

Employee

02-04-2019

If you request http://localhost:4502/libs/cq/workflow/content/inbox/list.json  as an admin, you get a list of all pending inbox items and their assignees. The code for how that list is generated is available in crx/de under /libs/cq/workflow/components/inbox/list/json.jsp

So you can model your code after the code used in that page and retrieve the results as an InboxItem array and  send your notifications.

Refer to the code in crx/de for the details on retrieving the data

Highlighted