Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

Need Help with AEM Approval Workflow Initiator

Avatar

Level 1

Hello there,

 

I'm currently  working on an AEM Approval Workflow, and I've hit a bit of a roadblock. I'm struggling to properly set up the initiator, and I could use some assistance.

 

Here's a breakdown of my workflow:

PRHebert_0-1710353653269.png

 

The Manager Approval task is a custom implementation of ParticipantChooser, where I retrieve the workflow initiator using:

 

 

String initiator = workItem.getWorkflow().getInitiator();

 

 

Afterward, I identify all the groups this user belongs to and match the author group to the approval groups. This part works smoothly when I manually start the workflow.

However, my goal is to streamline the process for authors by triggering the workflow automatically when the authors publish content using a launcher.

 

Here lies the issue: when the launcher triggers the workflow, the user is set to "workflow-service" which prevents me from finding the correct approvers.

 

I tried using the metadata

 

 

String initiator2 = workItem.getWorkflowData().getMetaDataMap().get("userId", String.class);

 

 

Or the workflowSession history but no luck so far.

 

 

* Get workflow history */
final List<HistoryItem> histories = workflowSession.getHistory(workItem.getWorkflow());

/* Get last item in workflow history */
final HistoryItem lastItem = histories.get(histories.size() - 1);

/* Get the user that participated in the last item */
final String lastUser = lastItem.getUserId();

 

 

Any other way I can achieve this programmatically or should I find another approach?
 
Thanks.
1 Accepted Solution

Avatar

Correct answer by
Level 3

@PRHebert - would the author who published the page be considered as initiator?

If yes, you can obtain property lastReplicatedBy from payload node.

 

View solution in original post

4 Replies

Avatar

Community Advisor


https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-retrieve-the-email-...
From workflow item ,you can retrieve user id by this code below

item.getWorkflow().getInitiator();

 

Code to get mail id .

 

resourceResolver = getResourceResolver(workflowSession.getSession());

UserManager manager = resourceResolver.adaptTo(UserManager.class);

Authorizable authorizable = manager.getAuthorizable(workItem.getWorkflow().getInitiator());

Value[] email = authorizable.getProperty("./profile/email");

System.out.println(email);

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-workflow-set-user-inpu...

 

Avatar

Correct answer by
Level 3

@PRHebert - would the author who published the page be considered as initiator?

If yes, you can obtain property lastReplicatedBy from payload node.

 

Avatar

Level 1

Thanks @VatsalGupta I was able to get unblock by using this.

lastReplicatedBy = payloadNode.getProperty("cq:lastReplicatedBy").getString();

Avatar

Administrator

@PRHebert Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni