How to add comments programmatically to an AEM workflow?

sticky notes
Photo by binh dang nam on Unsplash

Workflows can become complex depending on your business needs and in many situations it can be necessary or helpful to the end user to add comments dynamically/programmatically to your workflow. This allows the user to see a history of comments and identify issues, make decisions, and have more information on what happened to the workflow.

Adding comments on a Workflow process

Adding a comment dynamically to the workflow is very straightforward and uses the ability in AEM to add custom workflow steps. Check here if you’re not familiar with adding custom workflow steps. 

To be able to add a comment, you just need get the workItem MetaDataMap and put a property “comment”.

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;

public class DynamicCommentProcess implements WorkflowProcess {

    @Override
    public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
        throws WorkflowException {
        workItem.getMetaDataMap().put("comment", “<h4>Workflow comment</h4>“);
    }
}

You can make this as complex as you want as you can build the string dynamically. Notice that you can use HTML markup in your comments. You can add links, lists, headers, paragraphs, etc. 

Adding comments can be very helpful to your end user and nice them more information in one place, so they can either make a decision on their participant step, or consult that workflow history.

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

Leave a comment

Your email address will not be published. Required fields are marked *