Hello there,
I have a workflow that conditionally will be triggered once "cq:lastReplicationAction == Activate"
Issue is:
this property is stored with this value, and therefore does not represent exclusively when the page was published. therefore any other action such as submitting a dialog will also trigger the workflow.
Is there any way to solve this such as cleaning the property or verifying another property?
thanks in advance!
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
If you are concern to clearing cq:lastReplicationAction property after the workflow execution, you can consider using a custom flag or marker property instead. This approach involves setting a custom property on the page node to indicate that the workflow has been triggered and executed successfully. Here's how you can implement this alternative approach:
Add a Custom Flag Property:
Set the Flag Property in Workflow:
Check Flag Property in Workflow Model:
Implementation:
Here's a simplified example of how you can set the custom flag property using Java code within an AEM workflow step:
@Component(service = WorkflowProcess.class, property = {"process.label=Set Workflow Triggered Flag"})
public class SetWorkflowTriggeredFlagProcess implements WorkflowProcess {
private static final Logger LOGGER = LoggerFactory.getLogger(SetWorkflowTriggeredFlagProcess.class);
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
WorkflowData workflowData = workItem.getWorkflowData();
String path = workflowData.getPayload().toString();
try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(null)) {
Session session = resourceResolver.adaptTo(Session.class);
Node node = session.getNode(path);
// Set the custom flag property 'workflowTriggered' to true
node.setProperty("workflowTriggered", true);
session.save();
LOGGER.info("Successfully set 'workflowTriggered' flag for node: {}", path);
} catch (RepositoryException e) {
LOGGER.error("RepositoryException occurred: {}", e.getMessage());
throw new WorkflowException("RepositoryException occurred", e);
}
}
}
You can go through this and it may help you. You can address this issue by incorporating additional checks or properties to ensure that the workflow is triggered only when the page is activated, rather than any other action such as submitting a dialog. Here are a few approaches you can consider:
Custom Workflow Launcher:
Custom Metadata Property:
Additional Conditions in Workflow Model:
Event Listener:
Cleanup Mechanism:
Choose the approach that best suits your requirements and environment. It's often a good practice to combine multiple strategies for robustness and flexibility. Additionally, thoroughly test any changes to ensure they behave as expected in your AEM instance.
thanks for your answer.
already have a custom workflow launcher:
how can I achieve as you suggested, a double check on my workflow model in order to don't get false triggers. should I clear the field? If so is that a good practice and how do I do it?
If you are concern to clearing cq:lastReplicationAction property after the workflow execution, you can consider using a custom flag or marker property instead. This approach involves setting a custom property on the page node to indicate that the workflow has been triggered and executed successfully. Here's how you can implement this alternative approach:
Add a Custom Flag Property:
Set the Flag Property in Workflow:
Check Flag Property in Workflow Model:
Implementation:
Here's a simplified example of how you can set the custom flag property using Java code within an AEM workflow step:
@Component(service = WorkflowProcess.class, property = {"process.label=Set Workflow Triggered Flag"})
public class SetWorkflowTriggeredFlagProcess implements WorkflowProcess {
private static final Logger LOGGER = LoggerFactory.getLogger(SetWorkflowTriggeredFlagProcess.class);
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
WorkflowData workflowData = workItem.getWorkflowData();
String path = workflowData.getPayload().toString();
try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(null)) {
Session session = resourceResolver.adaptTo(Session.class);
Node node = session.getNode(path);
// Set the custom flag property 'workflowTriggered' to true
node.setProperty("workflowTriggered", true);
session.save();
LOGGER.info("Successfully set 'workflowTriggered' flag for node: {}", path);
} catch (RepositoryException e) {
LOGGER.error("RepositoryException occurred: {}", e.getMessage());
throw new WorkflowException("RepositoryException occurred", e);
}
}
}
Hi @caradeotario
Use both
"cq:lastReplicationAction == Activate" and cq:lastReplicated in order to trigger this.
"cq:lastReplicationAction" won't but cq:lastReplicated be changing for subsequent activation.
hello @arunpatidar
thats a good approach but since the value of cq:lastReplicated is a timestamp, what do I compare in order to check this?
Hi @caradeotario
I think in your use case you might to write a Event Listener
https://helpx.adobe.com/tr/experience-manager/kb/ReplicationListener.html
In your scenario, best way is to use workflow Launchers. Follow below link to understand Launchers.
@caradeotario you can add a condition to check the last modified date and replication date.
@caradeotario Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies