Hello everyone Good Morning, Hope you doing well!! We have one use case where if user creates any page at specific path we have to add few page properties automatically. To achieve this we created custom workflow and through launcher we triggering workflow. While creating page workflow gets trigger but until unless user complete step of workflow property not getting added at jcr:content. It should be auto and not require user to make complete step. Is anyone does similar kind of implementation?
Thanks.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
@Raja_Reddy Have you considered a Resource change Listener for your use case?
You can read about this here :
https://cqdump.joerghoh.de/2022/02/03/the-deprecation-of-sling-resource-events/
Views
Replies
Total Likes
@Raja_Reddy Have you considered a Resource change Listener for your use case?
You can read about this here :
https://cqdump.joerghoh.de/2022/02/03/the-deprecation-of-sling-resource-events/
Views
Replies
Total Likes
Hi @Raja_Reddy
To address your inquiry, allow me to pose a few more questions:
Is your customized code running successfully? If not, the problem might lie in the launcher configuration.
If the custom code is being invoked but the page properties are not updating, the issue could be related to your code or permissions.
Here is the sample code for workflow -
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
WorkflowData workflowData = workItem.getWorkflowData();
String payloadPath = workflowData.getPayload().toString();
String customProperty = args.get("customProperty", String.class); // get the custom property name from the dialog
String customValue = args.get("customValue", String.class); // get the custom property value from the dialog
ResourceResolver resolver = null;
try {
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "workflow-service");
resolver = resolverFactory.getServiceResourceResolver(param);
Resource resource = resolver.getResource(payloadPath);
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
if (node.hasProperty(customProperty)) { // check if the node already has the custom property
node.setProperty(customProperty, customValue); // update the custom property value
} else {
node.setProperty(customProperty, customValue); // add the custom property to the node
}
resolver.commit();
}
}
} catch (RepositoryException e) {
throw new WorkflowException(e.getMessage(), e);
} finally {
if (resolver != null) {
resolver.close();
}
}
}
Moreover, if the sole requirement is to add/update the custom page properties, have you considered exploring the option of event listeners?
In terms of performance, an event listener proves to be faster than a workflow. This is because it is triggered asynchronously, avoiding the overhead of creating workflow instances and nodes. On the contrary, a workflow tends to be slower and consumes more resources due to its involvement in multiple steps and transitions.
Views
Replies
Total Likes
Hi @Harwinder-singh and @Nitin_laad
Thanks for your response. I have fixed the issue on my end.
Views
Replies
Total Likes