Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Get Current User who invokes particular step in the workflow.

JJ_JayantJain
Level 1
Level 1

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 ?

 

 

workflow workflow activities
1 Accepted Solution
kalyan_venkat
Correct answer by
Level 3
Level 3

Hi @JJ_JayantJain 

 

In your execute method try the following

workItem.getWorkflow().getInitiator()

 -Kalyan

View solution in original post

8 Replies
Nupur_Jain
Community Advisor
Community Advisor

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

JJ_JayantJain
Level 1
Level 1

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

Hi @JJ_JayantJain 

 

In your execute method try the following

workItem.getWorkflow().getInitiator()

 -Kalyan

View solution in original post

fanindras
Level 5
Level 5

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

JJ_JayantJain
Level 1
Level 1
final List<HistoryItem> histories = wfSession.getHistory(workItem.getWorkflow()); final HistoryItem firstItem = histories.get(0); String lastParticipant= firstItem.getUserId();
JJ_JayantJain
Level 1
Level 1
List<HistoryItem> histories = wfSession.getHistory(workItem.getWorkflow()); HistoryItem firstItem = histories.get(0); String currentParticipant= firstItem.getUserId(); As per your response, tried the same code, but its not giving current user. It's giving last user.
airnavin30
Level 2
Level 2

@JJ_JayantJainIn such case Have you seen where this current user (expected user) value is stored in the path eg: /var/workflow/instances/server0/2021-03-03/update_asset_12/history/ ?
I think the way you are traversing to get the latest user is not correct you need to go to the reverse i.e. of the total for (i = HistoryItem length ; i>0 ; i--)  , Try once