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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Get Approvers name for a workflow

sreekalyanip
Level 3
Level 3

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

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
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();

View solution in original post

7 Replies
Arun_Patidar
Correct answer by
Community Advisor
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();

View solution in original post

smacdonald2008
Level 10
Level 10

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

AddUserAPp.png

smacdonald2008
Level 10
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.

Arun_Patidar
Community Advisor
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

smacdonald2008
Level 10
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" ;