Expand my Community achievements bar.

Getting the list of Notifications inbox items

Avatar

Level 3
Level 3

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

13 Replies

Avatar

Level 3

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.

Avatar

Level 3
Level 3

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.

Avatar

Level 3

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.

Avatar

Level 3
Level 3

No, that makes no sense.
We are talking server side code here.

Avatar

Administrator

Inbox items are just nodes. look at using the JCR api



Kautuk Sahni

Avatar

Community Advisor

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



Arun Patidar

Avatar

Level 3
Level 3

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!

Avatar

Employee

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

Avatar

Level 3
Level 3

Thank you for the reply, that looks promising!

I will go through it and let you know.

Thanks again

Avatar

Level 3

Hello @lir , were you able to get this working. I am in a similar situation and wondering if you can point me in right direction .

Avatar

Level 1

Thanks shunnar

I tried to customize /libs/cq/workflow/components/inbox/list/json.jsp. But the changes are reflecting only on Classic UI but not on Touch UI. I am working on AEM 6.4.3.

Avatar

Level 3

The logic to fetch or create data for TouchUI inbox is not at the front end as in case of classicUI but at the Java side. below is the basic flow:

-A request to '/aem/inbox' resolves to path '/libs/cq/inbox/content/inbox'

-This renders data per [1] which creates the html page per [2]

-At the same time [1] triggers a get request to fetch the data for the inbox page [3] which is handled by a servlet [4] and used by [2] to create the complete inbox page

-Further on logic goes to [5] and [6] to fetch the data per the logic

[1] /libs/cq/inbox/content/inbox/jcr:content/views/list/datasource

[2] /libs/cq/inbox/gui/components/inbox/inboxitem/list/list.html

[3] cq/inbox/gui/components/inbox/datasource/itemsdatasource

[4] com.adobe.cq.inbox.impl.servlet.ItemsDataSourceServlet.java

[5] com.adobe.granite.workflow.core.WorkflowSessionImpl.java

[6] com.adobe.granite.workflow.core.jcr.WorkItemManager.java

Avatar

Level 1

Hi,

Were you able to get this work?