We are trying to get publisher and use that in the custom email template to send a notification.
String currentUser = workItem.getCurrentAssignee();
The above returns "null"
String currentUser = resourceResolver.getUserID();
The above one returns "workflow-process-service"
Can we use workitem used to return the current user
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
List<HistoryItem> historyList = workflowSession.getHistory(workItem.getWorkflow());
int listSize = historyList.size();
HistoryItem lastItem = historyList.get(listSize-1);
final String publishStepParticpantUser = lastItem.getUserId();
This worked for me.
Workflow processes run in the background and are not directly tied to a specific user session. So, that is the reason you won't get current user details.
If you assign someone to the workflow step, you should get this correctly.
String currentUser = workItem.getCurrentAssignee();
Can you tell what is the problem you are trying to solve?
Hello @gkalyan
i am trying to print Publisher first name and last name.
Views
Replies
Total Likes
String currentUser = workItem.getCurrentAssignee();
Authorizable publisher = userManager.getAuthorizable(currentUser);
Returns null in this case
Views
Replies
Total Likes
String currentUser = workItem.getCurrentAssignee();
Only returns when you have a user assigned to the workflow step from the current user session.
Who is the publisher here? Is it the person activating/publishing the page or asset?
Views
Replies
Total Likes
Hi @gvaem
If I understand your question correctly, and you need to get the user who published the page, you can retrieve it through the cq:lastReplicatedBy property present on the jcr:content node of the payload path. You can then use this information to obtain the first and last name.
Hope this helps.
Regards
Ayush
If you are trying to get ID of the person who initiated the workflow then use:
workItem.getWorkflow().getInitiator();
Hi @gvaem
Maybe try getInitior method from Workflow, to know who started the workflow.
While
workItem.getCurrentAssignee(); // Returns the currently assigned user, respectively the info in which inbox the WorkItem "resides".
This returns the same initiator but not the current user.
Views
Replies
Total Likes
To get the current user in an AEM workflow:
1. Check Assignee: Ensure the workflow step has a valid assignee. workItem.getCurrentAssignee() should return the user if properly assigned.
2. Use Workflow Initiator: If getCurrentAssignee() returns null, try:
WorkflowSession workflowSession = workflowManager.getSession();
String initiator = workflowSession.getWorkflowInitiator(workItem.getWorkflow().getId());
3. Fallback: resourceResolver.getUserID() returns the authenticated user's ID but not the workflow step assignee.
Make sure the assignee is set correctly in your workflow process.
Returns "workflow-process-service"
Views
Replies
Total Likes
List<HistoryItem> historyList = workflowSession.getHistory(workItem.getWorkflow());
int listSize = historyList.size();
HistoryItem lastItem = historyList.get(listSize-1);
final String publishStepParticpantUser = lastItem.getUserId();
This worked for me.
Views
Likes
Replies