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.
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.
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.
No, that makes no sense.
We are talking server side code here.
Inbox items are just nodes. look at using the JCR api
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();
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.
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
Thank you for the reply, that looks promising!
I will go through it and let you know.