Workflow Launcher Compare Dates Condition | Community
Skip to main content
Level 3
January 29, 2025
Solved

Workflow Launcher Compare Dates Condition

  • January 29, 2025
  • 4 replies
  • 759 views

I'd like to create a workflow launcher based on dates. If cq:lastReplicated is newer than cq:lastModified, then kick off the workflow. Is this possible? I'm looking to trigger this only when a document has been published and it should not trigger when a document has been versioned (that's why I'm trying to add the date logic).

 

I've tried these settings:

 

Event Type: modified
Node type: dam:Asset
Path: /content/dam/mydocuments
Run modes: author
Conditions:

jcr:content/cq:lastReplicationAction==Activate
jcr:content/cq:lastReplicated>jcr:content/jcr:lastModified

 

Event Type: modified
Node type: dam:Asset
Path: /content/dam/mydocuments
Run modes: author
Conditions:

jcr:content/cq:lastReplicationAction==Activate
jcr:content/cq:lastReplicated-jcr:content/jcr:lastModified>=0

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

@gunars_v 

 

I would recommend using SampleReplicationPreprocessor or OnPublishEvent. Sharing samples for both.

 

SampleReplicationPreprocessor would act before publishing.

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adobe/acs/samples/replication/impl/SampleReplicationPreprocessor.java

 

OnPublishEvent will come into action after publishing 

https://aemsimplifiedbynikhil.wordpress.com/2022/10/20/automating-performing-tasks-on-replication-of-a-page-from-aem-author/ 

 

Workflow Laucher might not be able to deal with comparison operators like < & >

4 replies

aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
January 30, 2025

@gunars_v 

 

I would recommend using SampleReplicationPreprocessor or OnPublishEvent. Sharing samples for both.

 

SampleReplicationPreprocessor would act before publishing.

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adobe/acs/samples/replication/impl/SampleReplicationPreprocessor.java

 

OnPublishEvent will come into action after publishing 

https://aemsimplifiedbynikhil.wordpress.com/2022/10/20/automating-performing-tasks-on-replication-of-a-page-from-aem-author/ 

 

Workflow Laucher might not be able to deal with comparison operators like < & >

Aanchal Sikka
Shiv_Prakash_Patel
Community Advisor
Community Advisor
January 30, 2025

Hi @gunars_v ,

AEM Workflow Launchers do not support direct property comparisons, such as cq:lastReplicated > jcr:lastModified, as they only evaluate exact matches (==) or check for existence (!= null). Additionally, when an asset is published, cq:lastReplicated updates after the modification event, which can cause the launcher to misfire if the properties are not updated synchronously.

You can follow below approach to achieve this:

First Step: Trigger the workflow on publish using launcher. Modify the launcher configuration by setting the event type to modified, the node type to dam:Asset, and specifying the path as /content/dam/mydocuments, with run modes set to author. Use the condition jcr:content/cq:lastReplicationAction==Activate to ensure the workflow triggers only on publish events.

Second Step : Perform the date comparison logic inside a custom workflow step (Java code). Add a custom process step in your workflow model to programmatically compare cq:lastReplicated and jcr:lastModified.

import com.adobe.granite.workflow.WorkflowSession; import com.adobe.granite.workflow.exec.WorkItem; import com.adobe.granite.workflow.exec.WorkflowProcess; import com.adobe.granite.workflow.metadata.MetaDataMap; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ValueMap; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Calendar; @Component( service = WorkflowProcess.class, property = {"process.label=Check Last Replicated vs Last Modified"} ) public class CheckReplicationDateProcess implements WorkflowProcess { private static final Logger LOG = LoggerFactory.getLogger(CheckReplicationDateProcess.class); @Override public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) { ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class); if (resourceResolver != null) { String payloadPath = workItem.getWorkflowData().getPayload().toString(); Resource resource = resourceResolver.getResource(payloadPath + "/jcr:content"); if (resource != null) { ValueMap properties = resource.getValueMap(); Calendar lastReplicated = properties.get("cq:lastReplicated", Calendar.class); Calendar lastModified = properties.get("jcr:lastModified", Calendar.class); if (lastReplicated != null && lastModified != null) { if (lastReplicated.after(lastModified)) { LOG.info("Triggering workflow as cq:lastReplicated > jcr:lastModified for {}", payloadPath); // Continue workflow execution } else { LOG.info("Skipping workflow as lastModified is newer for {}", payloadPath); workflowSession.terminateWorkflow(workItem.getWorkflow()); } } } } } }

Regards,

Shiv Prakash
AmitVishwakarma
Community Advisor
Community Advisor
February 2, 2025

To create a workflow launcher based on cq:lastReplicated and cq:lastModified dates:

1. Configure the Workflow Launcher to trigger on the publish event (jcr:content/cq:lastReplicationAction == Activate).

2. Use a Custom Workflow Step for date comparison:
- Since Workflow Launchers can't handle < or >, implement a custom workflow step in Java to compare cq:lastReplicated and jcr:lastModified.
- In this step, compare the dates and decide whether to continue the workflow or terminate it.

Example Code for Custom Workflow Step:

public class CheckReplicationDateProcess implements WorkflowProcess { @9944223 public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) { Resource resource = ...; // Get resource from workItem Calendar lastReplicated = ...; // Get cq:lastReplicated Calendar lastModified = ...; // Get jcr:lastModified if (lastReplicated != null && lastModified != null && lastReplicated.after(lastModified)) { // Continue workflow } else { // Terminate workflow } } }



kautuk_sahni
Community Manager
Community Manager
February 10, 2025

@gunars_v Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni