Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Send Email workflow step comments in an email to initiator

Avatar

Level 3

I am setting up am approval/reject workflow to authorise activations. I am setting up an email template to send the initiator to let them know if the activation has been rejected. I would like to include the "comments" that can be put in the "Participant Step", if they decide to reject the request. Is there a way to do this? Will the "Send Email" step pickup the comments from the previous "Participant Step" that causes the rejection?

So far in the email template I have,

From: Global IT activation workflow <noreply@blah.com>
To: ${initiator.email}
Subject: Activation workflow rejection

Dear ${initiator.name},

The following item you submitted for activation approval has been rejected by one of the workflow approvers
${payload.path}

Please review the item and resubmit if required, taking notice of any comments below

Thank you
CQ Administration

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

If the comment you want to include is available in workflow instance metadata you can access it like this:

${item.workflow.data.[metadata property name]}

Hope this helps,

Will

View solution in original post

5 Replies

Avatar

Correct answer by
Employee

Hi,

If the comment you want to include is available in workflow instance metadata you can access it like this:

${item.workflow.data.[metadata property name]}

Hope this helps,

Will

Avatar

Level 3

No sorry, its in the actual step item details. I can get the Workflow instance "Start comment" using, ${instance.data.startComment}

Its the comment that actually gets entered into the participant step when the workflow user actions their inbox. I think I can get the step ID using, ${item.id}

That give me something like VolatileWorkItem_node9_etc_workflow_instances_2015-06-10_model_49688341059757941

I believe the comment is placed under [workflowinstance]/workitem/metadata.comment , as it is there on the archived step under the history node, but I don't seem to be able to get this property.

It may be that this data is just not accessible using the email templates.

Avatar

Level 10

You may have to write a custom workflow step and use the JCR API to get this node value. 

Avatar

Level 2

If anyone comes up with a solution, I would like to know.  We are going to attempt to do the same!

Avatar

Level 2

In a custom workflow step use this below code to fetch the comments.

 

public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
          

   
          

          HistoryItem previousHistoryItem;
              String stepType;

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

            Iterator<HistoryItem> historyIterator =history.iterator();

            while(historyIterator.hasNext()){

                    previousHistoryItem = historyIterator.next();

                    String comments=previousHistoryItem.getComment();

                    //OR

                    String someproperty=previousHistoryItem.getWorkItem().getMetaDataMap().get("comment", String.class);

    }