AEM Workflow - Current user for a process step | Community
Skip to main content
January 30, 2025
Solved

AEM Workflow - Current user for a process step

  • January 30, 2025
  • 7 replies
  • 1845 views

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 

Best answer by gvaem
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.

 

7 replies

gkalyan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
January 30, 2025

@gvaem 

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?

gvaemAuthor
January 30, 2025

Hello @gkalyan 

i am trying to print Publisher first name and last name.

gvaemAuthor
January 30, 2025
String currentUser = workItem.getCurrentAssignee();
Authorizable publisher = userManager.getAuthorizable(currentUser);

Returns null in this case

ayush-anand
January 30, 2025

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

aanchal-sikka
Community Advisor
Community Advisor
January 31, 2025

@gvaem 

 

If you are trying to get ID of the person who initiated the workflow then use:

workItem.getWorkflow().getInitiator();

 

 

Aanchal Sikka
arunpatidar
Community Advisor
Community Advisor
January 31, 2025

Hi @gvaem 

Maybe try getInitior method from Workflow, to know who started the workflow.

https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/com/adobe/granite/workflow/exec/Workflow.html#getInitiator-- 

 

While

workItem.getCurrentAssignee(); // Returns the currently assigned user, respectively the info in which inbox the WorkItem "resides".

 

Arun Patidar
Harwinder-singh
Community Advisor
Community Advisor
January 31, 2025

@gvaem try 

Authorizable publisher = userManager.getAuthorizable(workItem.getWorkflow().getInitiator());

gvaemAuthor
January 31, 2025

This returns the same initiator but not the current user.

AmitVishwakarma
Community Advisor
Community Advisor
February 1, 2025

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.

gvaemAuthor
February 3, 2025

Returns "workflow-process-service"

gvaemAuthorAccepted solution
February 3, 2025
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.