AEM Business Practitioner study materials
AEM Business Practitioner study resources

Publishing Approval Workflow with Scheduled Release and Version Comparison

AEM Business Practitioner · Put your knowledge to work in context.

All case studies

Publishing Approval Workflow with Scheduled Release and Version Comparison

A healthcare organization uses AEM Sites to manage patient education content. Due to regulatory requirements, all content must go through a two-step approval: a medical reviewer and a compliance officer. Content authors create pages and submit for approval. The reviewers need to see a diff of changes since the last approved version. Once approved, content should be published automatically at a scheduled time (e.g., every Tuesday at 2 AM). The organization also needs to keep a record of who approved what and when, for audit purposes. Currently, they use a manual process with emails and spreadsheets, which is error-prone and slow. They want to automate this using AEM workflows and ensure that only approved content is published. The content includes text, images, and PDFs. The team has some developers but prefers configuration over custom code.

1. Design a workflow that incorporates two-step approval, version comparison, scheduled publishing, and audit logging.

Read the worked answer

Create a custom workflow model with the following steps: 1) Start on page activation request. 2) Assign a task to the medical reviewer group. In the task, include a link to the page's version history and a diff tool (AEM has a built-in diff for versions). 3) After medical approval, assign a task to the compliance officer. 4) After compliance approval, set a property on the page (e.g., 'approved=true') and record approver details and timestamp in metadata. 5) Use a workflow step to schedule activation: use the 'Activate' step with a delay, or use the 'Scheduled Activation' feature via the workflow's 'Timer' step. Alternatively, use the 'Publish' step and set the time via a process argument. For audit, use the workflow history and also write to a custom audit log (e.g., a node under /var/audit) with approver, timestamp, and version. Use the 'Version Comparison' step to show diff. Since custom code is to be minimized, use the built-in 'Version Compare' feature in the task UI. For scheduled publishing, use the 'Scheduled Activation' option in the page properties, but that doesn't tie to workflow. Better: use a workflow step that waits until the scheduled time using the 'Timer' step, then activates. However, long-running workflows may not be ideal. Alternative: on approval, set the page's on/off time to the next Tuesday 2 AM, and use a separate scheduled job to activate pages with approved status at that time. This can be done with a scheduled workflow or a cron job. For audit, the workflow history provides a record. This uses mostly configuration.

2. How would you ensure that the scheduled publishing only occurs for content that has passed both approvals and that the published version is the one that was approved?

Read the worked answer

On completion of both approvals, the workflow sets a metadata property 'approvalStatus=approved' and stores the approved version number (e.g., 'approvedVersion=1.2'). Then, a scheduled job (e.g., a Sling Scheduled Job or a workflow triggered by a cron) runs every Tuesday at 2 AM, queries for pages with 'approvalStatus=approved' and 'scheduledPublishDate' <= now. For each page, it checks if the current version matches 'approvedVersion'. If yes, it activates the page and resets 'approvalStatus' to 'published'. If the current version is newer, it skips and notifies the author that the approved version is outdated. This ensures only the approved version is published. The scheduled job can be implemented as a workflow with a timer or as a custom scheduled service. Since custom code is preferred to be minimal, use a workflow with a timer step that waits until the scheduled time, then checks version and activates. However, long-running workflows may be problematic if the server restarts. A more robust approach is to use a scheduled job that queries and activates. This can be configured via a workflow launcher on a scheduled node. The audit log is updated at activation time with the version and approver info. This ensures compliance.