Create a custom workflow

In this post, we will see how to implement a workflow using AEM. As the name suggests, a workflow represents a step-by-step process to accomplish a common task. For example, author creates the content. Then, the content goes to an editor for approval. After the approval, the content can be published. As usual, we will see a simple implementation.

(Get the code samples from my GitHub account.)

After executing the workflow, we will log the name of the page into the custom log. I know it’s so simple – but it will give you an idea of how executing a workflow can kick off a method in a bundle.

  1. Create a WorkflowImpl class in the com.aemcompany.myproject.impl package.
    public class WorkflowImpl implements WorkflowProcess{
    private Logger log = LoggerFactory.getLogger(this.getClass());
    public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException
    WorkflowData data = workItem.getWorkflowData();
    String payload = (String)data.getPayload();;
  2. Implement WorkflowProcess interface.
  3. Implement WorkflowProcess interface.
  4. Use a WorkflowData object to get the workflow data.
  5. Get the payload from the workflow data.
  6. Write it to the log.

Now let us create a workflow using the AEM interface.

  1. Go to the workflow console:
  2. Select New.
  3. Enter the name.
  4. Double-click the newly created workflow.
  5. Drag and drop a process step
  6. Select AEM Workflow Process we created.
  7. Select Handler Advance. Selecting this advances the workflow to the next step automatically, without executing any additional steps.
  8. Select OK.

Let us execute the workflow.

  1. On the page we created, go to the Workflow tab.
  2. Select AEM Company and select Start Workflow.
  3. Select Step 1 and select Complete.
  4. Select OK.
  5. Open the log.

See the name of the page where it’s executed is added to the log. It was a small demo – hope it gave a basic idea of implementing workflow.

See you soon.


Comments are closed.