Skip to main content

Day 15: Custom Workflows in AEM

AEM Developer Series

A workflow enables us to automate a wide range of activities in AEM. A workflow consists of steps that are executed in a specific order. Each step performs a distinct activity such as activating a page or sending an email message.

Workflows can interact with assets in the repository, user accounts, and services. Therefore, workflows can coordinate complicated activities that involve any aspect of AEM.

Many useful workflow models are provided out of the box with AEM. In addition, any number of custom workflow models, tailored to the specific needs of our project, can be also be created.

In this post, we will be creating a custom workflow that will read the user passed data and logs it. So, without wasting much time, let's dive into the code.

Custom Workflow

  • To create a custom workflow component, go to your project folder under /apps in CRXDE and create a component with the following configuration.
Create a component
  • Now create cq:dialog node with the following configuration -
  • Now create a new node cq:ediConfig of type cq:EditConfig underneath workflowDemo node with the following configuration - 
  • The PROCESS value is the name of the class that will have Java backend logic.
  • Create a java class named CustomWorkflow and paste the following code in it.
  • Here we are implementing the WorkflowProcess interface and defining the process.label property which defines the name of the workflow step.
  • Deploy the code on your AEM server.
  • Navigate to http://<host>:<post>/libs/cq/workflow/admin/console/content/models.html and click on Create >> Create Model and enter the Title of the workflow as below and configure it as per the below screenshots
Create a workflow model
Edit the workflow model
Add the steps in the workflow

  • Drag and drop the steps from the side rail and double click on the Custom Workflow step.
Add values in the workflow

  • Go to the Properties tab and enter sample values and save the dialog. Now click on Sync.
  • Now go to sites console and run the workflow as per below screenshots.
Create a workflow on page
Select Workflow Model
Inbox notifications
Complete the workflow step
  • After completing the workflow, you will see the following traces in logs

17.10.2018 20:30:51.869 *INFO* [JobHandler: /var/workflow/instances/server0/2018-10-17_1/customWorkflow_11:/content/we-retail/language-masters/en/women] org.redquark.demo.core.workflows.CustomWorkflow Executing the workflow
17.10.2018 20:30:51.874 *INFO* [JobHandler: /var/workflow/instances/server0/2018-10-17_1/customWorkflow_11:/content/we-retail/language-masters/en/women] org.redquark.demo.core.workflows.CustomWorkflow Text: Custom Workflow Testing Demo
17.10.2018 20:30:51.874 *INFO* [JobHandler: /var/workflow/instances/server0/2018-10-17_1/customWorkflow_11:/content/we-retail/language-masters/en/women] org.redquark.demo.core.workflows.CustomWorkflow Date: 2018-10-17T19:17:00.000+05:30


Congratulations!! 🙋 we have successfully created a custom workflow and read passed data using metadataMap object. I hope you enjoyed this post.

You can find the complete code of this project on my GitHub in this commit. Feel free to fork or open issues, if any.

I would love to hear your thoughts on this and would like to have suggestions from you to make it better. 

Feel free to befriend me on Facebook, Twitter or Linked In or say Hi by email.

Happy Coding 😃


Popular posts from this blog

Day 00: AEM Developer Series

Hello everyone! Welcome to this AEM development series. We can all see the revolution of Digital Marketing today. Companies are dying to be a part of it and they have made this a war for the Digital Marketing tools.
Adobe is way ahead in this war and has gained a lot of market capture. They are leaders in the Digital Marketing platforms since 2014-15. One of the flagship product in Adobe's Digital Marketing suite is Adobe Experience Manager (AEM).
Since AEM is in huge demand, the people who know how to develop on AEM are also in huge demand. But developing on AEM is not easy as it is made up of various open-source technologies such as Apache Felix (OSGi), Apache Sling, Apache Oak and Adobe's own technologies like Granite, HTL etc. Learning all these technologies in conjunction can sometimes become confusing and frustrating 😫.
When I first started learning AEM in 2016, I was dumbfounded to see there is so much going on under the hood. I then spent months to gather all the res…

Day 05: Working with Sling Servlets in AEM

Day 03: Setting up AEM Development Environment