Get Current User who invokes particular step in the workflow. | Community
Skip to main content
August 24, 2020
Solved

Get Current User who invokes particular step in the workflow.

  • August 24, 2020
  • 3 replies
  • 2426 views

I  tried to get current user using session and authorizable. But none of them giving the current user who invokes the particular step.

Is there any other way to get the current user details ?

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kalyan_venkat

Hi @jj_jayantjain 

 

In your execute method try the following

workItem.getWorkflow().getInitiator()

 -Kalyan

3 replies

Nupur_Jain
Adobe Employee
Adobe Employee
August 24, 2020

Hi @jj_jayantjain 

 

You can use getInitiator() method of Workflow API to get the user ID of the user who started the workflow. 

 

Refer https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/adobe/granite/workflow/exec/Workflow.html API to get to know more about this particular method.

 

String getInitiator() Returns the initiator of the Workflow instance. Returns: The user who initiated the Workflow.

 

Hope it helps!

Thanks!

Nupur

August 24, 2020

workItem.getWorkflow().getInitiator();
Gives the details of user who initiated the workflow, which is not my requirement.

I need to get the detail of the user, who currently logged in and running a particular step(process step or dynamic participant step).

kalyan_venkatAccepted solution
Level 3
August 24, 2020

Hi @jj_jayantjain 

 

In your execute method try the following

workItem.getWorkflow().getInitiator()

 -Kalyan

Fanindra_Surat
Community Advisor
Community Advisor
August 24, 2020

@jj_jayantjain ,

I understand that you need the userId of the most recent participant in your workflow. This can be fetched as follows:

 

Step1: workflowSession.getHistory. This should return the history of workflow:

List<HistoryItem> histories = workflowSession.getHistory(workItem.getWorkflow());

Step2: The most recent action of the participant user should be the first item in the histories list at index 0, and this can be accessed as:

HistoryItem recentHistory = histories.get(0);

 Step3: The recent user id can be fetched using the getUserId method of HistoryItem:

String recentUser = recentHistory.getUserId();

 

Please let me know if this works.

August 24, 2020
final List<HistoryItem> histories = wfSession.getHistory(workItem.getWorkflow()); final HistoryItem firstItem = histories.get(0); String lastParticipant= firstItem.getUserId();