AEM workflow comments

Photo by Miguel Á. Padriñán from Pexels

How to access workflow comments?

The default workflow participant step allows you to add comments choosing which process to go to. Although AEM stores the comments in the workflow itself, you can only see them on the comments tab of the workflow. What if you want to send the comments on an email or send them somewhere else?

This post will show you how to access the comments.

Workflow Process

The comments get saved in the repository in the workflow history for that Participant Step. You can check your workflow history in the repository under /var/workflows/instances

The best way to have access to the comments is to add a workflow process immediately after the participant. This process should get the last item of the workflow history (the most recent) and get the comment on that item. Remember that the current process only gets added to the history after it has completed.

Workflow participant step and comment process
Workflow participant step and comment process

The Process comments Workflow Process code would look like the following. Notice that the code will send an email to the initiator with the comment.

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.HistoryItem;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

    service = WorkflowProcess.class,
    property = {"process.label=Comment Notification Process"})
public class CommentNotificationProcess implements WorkflowProcess {
  @Reference private EmailService emailService;

  public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
      throws WorkflowException {
    String initiator = workItem.getWorkflow().getInitiator();

    List<HistoryItem> history = workflowSession.getHistory(workItem.getWorkflow());
        HistoryItem last = history.get(history.size() - 1);
            emailService.sendComment(initiator, comment);

Additionally, this can be improved by using custom arguments as described here to be able to customise groups or emails you might want to send the comments to.

Get in touch on LinkedIn or leave comments for any questions or suggestions.

Leave a Reply