Expand my Community achievements bar.

SOLVED

AEM Workflow - Current user for a process step

Avatar

Level 3

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 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 3
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.

 

View solution in original post

12 Replies

Avatar

Community Advisor

@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?

Avatar

Level 3

Hello @gkalyan 

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

Avatar

Level 3
String currentUser = workItem.getCurrentAssignee();
Authorizable publisher = userManager.getAuthorizable(currentUser);

Returns null in this case

Avatar

Community Advisor

@gvaem 

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?

Avatar

Level 6

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

Avatar

Community Advisor

@gvaem 

 

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

workItem.getWorkflow().getInitiator();

 

 


Aanchal Sikka

Avatar

Community Advisor

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/wor... 

 

While

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

 



Arun Patidar

Avatar

Community Advisor

@gvaem try 

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

Avatar

Level 3

This returns the same initiator but not the current user.

Avatar

Level 7

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.

Avatar

Level 3

Returns "workflow-process-service"

Avatar

Correct answer by
Level 3
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.