AEM Developer Series
- Day 00: AEM Developer Series
- Day 01: Introduction to AEM
- Day 02: AEM Architecture
- Day 03: Setting up AEM Development Environment
- Day 04: Developing First OSGi Bundle
- Day 05: Working with Sling Servlets in AEM
- Day 06: Playing with Sling Post Servlet
- Day 07: Creating your first component in AEM
- Day 09: Dueling with Java Use API
- Day 10: Getting to know Sling Models
- Day 11: Client Libraries in Action
- Day 12: Creating your custom OSGi Configuration
- Day 13: Schedulers in AEM
- Day 14: Eventing in AEM
- Day 15: Custom Workflows in AEM
- Day 16: Creating JMX Beans in AEM
- Day 17: Working with QueryBuilder API
- Day 18: Working with Granite Datasources in AEM
- Day 19: Replication API in Action
- Day 20: Working with Users and Groups in AEM
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.
- 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|
|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.
Happy Coding 😃