Get Approvers name for a workflow | Community
Skip to main content
Level 3
July 23, 2018
Solved

Get Approvers name for a workflow

  • July 23, 2018
  • 7 replies
  • 2086 views

How can we get approvers name who has approved a workflow step for a workflow who belongs to a publisher group.

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 arunpatidar

Hi,

you meant last task approved by users? If Yes you can try below code

Note : below code only check last task if want to check all you can loop through by list.

List<HistoryItem> historyList = session.getHistory(item.getWorkflow());

  int listSize = historyList.size();

  // log.info("listSize = {}", listSize);

  HistoryItem lastItem = historyList.get(listSize - 1);

  String lastComment = lastItem.getComment();

  String lastAction = lastItem.getAction();

  String lastUser = lastItem.getUserId();

7 replies

smacdonald2008
Level 10
July 23, 2018
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
July 23, 2018

Hi,

you meant last task approved by users? If Yes you can try below code

Note : below code only check last task if want to check all you can loop through by list.

List<HistoryItem> historyList = session.getHistory(item.getWorkflow());

  int listSize = historyList.size();

  // log.info("listSize = {}", listSize);

  HistoryItem lastItem = historyList.get(listSize - 1);

  String lastComment = lastItem.getComment();

  String lastAction = lastItem.getAction();

  String lastUser = lastItem.getUserId();

Arun Patidar
smacdonald2008
Level 10
July 23, 2018

Arun - does that code show the WF user whom approved the payload as shown here.

smacdonald2008
Level 10
July 23, 2018

If so - that would make a nice artilce - i searched the Java docs and talked to ppl. I am going to test this.

arunpatidar
Community Advisor
Community Advisor
July 23, 2018

Hi Scott,

I think, we can read all the properties of transitions. For example below property can be read using JCR Node API

Node nsession.getSession().getNode(lastItem.getWorkItem().getId());

Below is example of process step which simply add all history task in DB in form of json

aem63app-repo/WriteWFdetailsInDBProcess.java at master · arunpatidar02/aem63app-repo · GitHub

Arun Patidar
smacdonald2008
Level 10
July 23, 2018

I tested this code and it did report whom approved the workflow --

//Gets the User from approves the payload

private String getUserWhomApproved(WorkflowSession wfsession,WorkItem item)

{

try{

List<HistoryItem> historyList = wfsession.getHistory(item.getWorkflow());

  int listSize = historyList.size();

  // log.info("listSize = {}", listSize);

  HistoryItem lastItem = historyList.get(listSize - 1);

  String lastComment = lastItem.getComment();

  String lastAction = lastItem.getAction();

  String lastUser = lastItem.getUserId();

  return lastUser;

}

   

    catch (Exception e)

    {

    e.printStackTrace()  ;

    }

  return "error  - no user" ;

 

smacdonald2008
Level 10
July 23, 2018

We captured this information that Arun provided in this related HELPX article -- https://helpx.adobe.com/experience-manager/using/aem64_workflow_servlet.html