AEM Workflow Custom Process

AEM provides a set of pre-defined workflow process that cover common scenarios, but sometimes these built-in features may not fully handle the complexities of specific workflows. In such cases, AEM allows developers to create custom processes, enhancing the functionality of standard workflows to meet unique requirements.
In order to create custom workflow process, you'll need to implement the WorkflowProcess interface and override the execute method.
workflow / process /
@Component(service = { WorkflowProcess.class }, property = { "process.label=Process Article Form Data"}) public class ArticleFormDataProcess implements WorkflowProcess { private final String JCR_PATH = "JCR_PATH"; private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Override public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { WorkflowData workflowData = workItem.getWorkflowData(); String payloadType = workflowData.getPayloadType(); if (StringUtils.equals(payloadType, JCR_PATH)) { String pagePath = workflowData.getPayload().toString(); logger.debug("Payload: {}", pagePath); } } }
Let's create a workflow model to consume the custom process. Navigate to the Tools then select Workflow and click on Models. Proceed by creating a new workflow model with a suitable name.
AEM Workflow New Model
Select the newly generated workflow model and click on the Edit button to incorporate workflow steps. Remove the default "Step 1" and drag the Process Step into the workflow model. Afterwards, configure this step with the custom process as illustrated below.
AEM Workflow Custom Process
To initiate the workflow, you have two options: either pick the workflow from the workflow models page and choose any page as the payload, or directly start the workflow from the page itself. Once the workflow is started, debug logs will be appended to your log file. You can tailor the custom process according to the requirements of your project.