Get Approvers name for a workflow

Accepted Solutions (1)

Accepted Solutions (1)

Arun_Patidar
MVP
23-07-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();

Answers (6)

Answers (6)

smacdonald2008 23-07-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" ;

 

Arun_Patidar
MVP
23-07-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());

Screen Shot 2018-07-23 at 5.22.07 PM.png

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