Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Get Approvers name for a workflow

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 10

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

AddUserAPp.png

Avatar

Level 10

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

Avatar

Community Advisor

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



Arun Patidar

Avatar

Level 10

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" ;