Article summary

 

Summary

Discusses common AEM workflow concepts and tasks, including how to create a workflow, invoke it, and monitor it. 

In addition to reading this article, it is recommended that you also watch the following Ask the AEM Community Experts from March 2015: AEM Workflow.  

Digital Marketing Solution(s) Adobe Experience Manager (Adobe CQ)
Audience
Developer (intermediate)
Required Skills
Java
Tested On Adobe Experience Manager 6

Introduction

Workflows enable you to automate Experience Manager activities. Workflows consist of a series 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 Experience Manager services. Therefore, workflows can coordinate complicated activities that involve any aspect of Experience Manager.

For example, a key application of Experience Manager is Web Content Management (WCM), which enables you to generate and publish pages to your website. This functionality is often subject to organizational processes, including steps such as approval and sign-off by various participants. These processes can be represented as workflows, which in turn can be defined within Experience Manager, then applied to the appropriate content pages.

Many useful workflow models are provided with Experience Manager. In addition, any number of custom workflow models, tailored to the specific needs of your project, can be defined using the Workflow console. A workflow is made of steps. Automated steps, also called process steps, can be defined by using either an ECMA script or a service (a Java class in a bundle). For information about creating a custom workflow step by using a Java service, see Creating custom AEM workflow steps that send email messages.

workflow

This article covers the following subjects:

  • Create an AEM workflow that activate AEM pages.
  • How to invoke the AEM workflow.
  • How to check if the workflow is successful.
  • How to invoke a workflow using workflow Launcher.
  • Workflow sessions.
  • Managing data in your workflow.
  • Monitor performance of workflows.
  • Managing workflow throughput.

Note:

For more information about Workflows, see Workflow Overview.

Create an AEM workflow that activate AEM pages

You can create a workflow model to define a series of steps to execute. Workflow models include Flow Start and Flow End steps that represent the beginning and end of the workflow. The model created in this example simply activates a page.

 

workflowmodel

To create an AEM workflow model:

  1. Navigate to the workflow console: http://localhost:4502/libs/cq/workflow/content/console.html.
  2. Click the New button that is located on the upper left side of the page.
  3. Enter the title AEMExperts and then click OK.
  4. Double click the workflow to view the model.
  5. Because you are creating an automated workflow (no human interaction), delete 1st step.
  6. Under the WCM Workflow section in sidekick, select Activate Page / Assets.
  7. Click the Save button.  

Invoke the AEMExperts workflow

You can publish a page by invoking the AEMExperts workflow. To demonstrate this workflow, make a change to the page located at: 

http://localhost:4502/cf#/content/geometrixx/en/products/triangle.html

For example, modify the page by styling the text component. Bold the text in the text component, as shown in the following illustration. 

Geo1

Using the AEMExperts workflow, you can publish this AEM page. 

 

InvvokeWorkflow

Once this worlflow executes, the changes made to the triangle.html page are published and the changes are visible on the AEM publish instance, as shown here. 

Geo2

To invoke an AEM workflow:

  1. Navigate to the URL: http://localhost:4502/siteadmin#/content/geometrixx/en/products.
  2. Open the triangle page and underline some text..
  3. Click the Workflow button and select AEMExperts.
  4. Click Start.

Determine if a Workflow is successful

You can determine if a worflow was successful or not by viewing the Workflow Archive tab. A workflow can have one of the following status values:

  • RUNNING: The workflow instance is running.
  • COMPLETED: The workflow instance has been successfully ended.
  • SUSPENDED: The workflow instance has been suspended.
  • ABORTED: The workflow instance has been terminated.
  • STALE: Progression of the workflow instance requires that a background job executes, however the job cannot be found in the system. This situation can occur when an error occurs when executing the workflow.
Arch

The Workflow Archive tab displays the following information:

  • Status: The status of the workflow. 
  • Initiator: The AEM user whom started the workflow
  • Start Time: The start time.
  • End Time: The end time.
  • Workflow Model: The workflow model
  • Model version: The verison of the workflow
  • Payload: The content (for example, a page) on which the workflow is used.

To view the status of a workflow:

  1. Navigate to the workflow console: http://localhost:4502/libs/cq/workflow/content/console.html.
  2. Click the Archive tab.  

Using Workflow Launcher

Workflow launcher lets you automatically invoke a workflow based on conditions.
That is, a change to AEM JCR content. For example, when a page is modified. In this example, the workflow launcher is configured to invoke a workflow when content under /content/geometrixx is modified. The result is the AEMExperts workflow automatically publishes the page.
 

launcher

You can achieve the behavior of a workflow launcher also by using code. But in many cases, it makes sense to provide functionality as workflow steps, because the flexibility to reconfigure individual steps is much higher. You don’t need to change any code or configuration to reconfigure a workflow, disable a certain workflow step and disable the workflow completely.

To configure workflow launcher, perform these tasks:

1. Go to workflow console at http://localhost:4502/libs/cq/workflow/content/console.html.
2. Click the Launcher tab.
3. Click the Add button at the top left of the page.
4, Add the following information:

  • Event Type: modified
  • Node Type: nt:unstructured
  • Path: /content/Geometrixx
  • Workflow: AEMExperts
  • Description: Activates Geometrixx pages
  • Activate: leaved enabled
  • Exclude List: Leave empty
  • Run Mode(s): Author

5. Click OK.

Working with Sessions

You can create a custom workflow step to perform business logic within an AEM workflow. For information, see Creating custom AEM workflow steps that send email messages.

When developing a custom workflow step, often you need to acquire a JCR session from a workflow session. You can obtain a Granite workflow session using this code:

session = workflowSession.adaptTo(javax.jcr.Session.class);

You can develop a CQ workflow session (will be deprecated at some point) using this code:

session = workflowSession.getSession();

You can use this session to process the payload. When working with sessions, use a one of these ways to obtain a session; do not acquire your own. Also, keep these points in mind: 

  • Do not save a session. Workflow engine saves the session for you
  • More efficient and better error handling if you let the workflow engine save session
  • The workflow engine attempts to run as many steps together at one time as possible
     

Managing data in your workflows

When working with workflow data, there are some concepts to consider:

  • Payload: Typically a path in the repository (for example, an AEM page). You can add status or other data associated with the payload (for example: DAM Update Asset)
  • WorkItem metadata: Can store information related to an individual step. Most useful for steps which do not complete immediately (participant step, external process) . Useful for populating when a workflow starts, and sharing amongst different workflow steps

You can pass data between workflow steps. To assign data, use the following method:

workItem.getWorkflowData().getMetaDataMap().put(“someKey”, “someValue”);

You can retrieve data on subsequent steps:

workItem.getWorkflowData().getMetaDataMap().get(“someKey”, String.class);
 

The following illustration shows the steps that occur when a workflow is invoked and how AEM manages the data (payload).

workflows

Monitor Workflow Performance 

You can monitor the performance of workflows by viewing the workflow reporting interface at: 

http://localhost:4502/etc/reports/workflowreport.html

You can view the following data:

  • Details on number of workflows and duration
  • Links with breakdowns for individual workflows
  • Individual steps (grouped) are timed
  • Execution optimized, which skews results slightly
     
workflowMonitor

You can also view the sling job page located at:

http://localhost:4502/system/console/slingevent

This page monitors what has happened and what is currently happening. 

workflowoutput

Managing Workflow Throughput

You can limit the number of threads used to execute worklfows. This can be configured globally for entire system, or for an individual workflow. 

  • Globally: edit “Granite Workflow Queue”
  • Per workflow: create new Sling Job Queue Edit “maximum parallel jobs”
     
workflowthreads

Note:

For more information, see CONCURRENT WORKFLOW PROCESSING.

See also

Congratulations, you have just worked through AEM workflow tasks. Please refer to the AEM community page for other articles that discuss how to build AEM services/applications.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy