Wednesday, 8 May 2024

Workflow in AEM (Part -1)

 What is Workflow?

  • It allows you to automate your tasks, which can be individual tasks or a series of tasks performed sequentially, mainly on content, such as pages and assets.
  • When you create a Workflow, the first thing you need is a Workflow Model. The Workflow Model is the heart of the workflow, as it contains a series of steps. Each step can perform a specific task, providing complete functionality. You can reuse these steps in any workflow.
  • There are 'n' number of steps available out of the box in AEM. However, you can also create your own steps.



When you create a Workflow Model, it is stored in two places in the repository.
  • Model Design [/conf/global/setting/workflow/model]
  • Runtime Model [/var/workflow/models]
When we talk about steps, for example, step 1, step 2, up to step 'n', there are four types.

  • Container Step: When we want to trigger another model or workflow, for example, when we want to execute or trigger a child workflow, we use a Container Step. 
  • Participant Step: When we require human interaction within a workflow, such as assigning tasks to someone, we use a participant step.
  • Decision Step: When you need to perform a task based on a condition, typically when branching is required in your workflow, you use a decision step.
  • There are two types of decision steps:
  1. AND
  2. OR
  • Process Step: Custom workflow processes are implemented using the process step.
After creating a workflow model, it can be invoked in three main ways.

  1. Launcher
  2. API/Code
  3. Manually
  • Launcher:- When we want to automate the triggering of a workflow, we create a Launcher.
  • API/code:-When we want to trigger this workflow using code, we can do so in any backend module, such as a servlet or Sling model. This can be achieved using API/Code.
  • Manually:- In AEM, we have a console where we can trigger this workflow manually.
How do you write a Workflow Model?




  • Models: All the Out of the Box models will be present under models, and you can create your own model.
  • Instances: All the running instances of that workflow will be present under 'instances.
  • Launchers: All the Out Of the Box launchers will be present under 'launchers', and you can create your own launcher as well.
  • Archive:- All the successful workflow instances will be present under Archive.
  • Failures:- In case your workflow fails due to any reason, the instances of failed workflows will be present under 'Failures'.
Step1:



Step 2:



Step 3:



Step 4:




Step 5:



Step 6:



Step 7:

Manually Trigger Workflow



Step 8:



How to trigger a workflow through the Launcher

Step 1:

After create Workflow



Step 2:


Step 3:




Step 4:



How to trigger a workflow through the API/Code




  • For triggering a workflow via API in the backend, first, you need a WorkflowSession.
  • Once you have the WorkflowSession, you then need a WorkflowModel. You need the WorkflowModel when you are using the WorkflowSession to pass the exact path in your Runtime model, which you can then trigger.
  • After that, you need WorkflowData, which you use with the WorkflowSession, essentially using the payload of your workflow.
  • Once you have both the WorkflowModel and WorkflowData, you can start the workflow by using the WorkflowSession and passing both the WorkflowModel and WorkflowData.

We are using a servlet as a backend module to trigger the workflow using API/code.

Step1:


Step 2:


Step 3:

In error.logs


Step 4:



Quotes
Success is the sum of small efforts - repeated day in and day out.

Thanks for Reading
Matri Sharma

No comments:

Post a Comment

Servlet in AEM/Sling Servlet

  What is Servlet? A servlet is a Java class that runs on the server side where the application resides. It acts as a middle layer between t...