Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM Custom Workflow -Page created Event -Luncher

Avatar

Community Advisor

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.



Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Avatar

Community Advisor

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.

Avatar

Community Advisor

Hi @Harwinder-singh and @Nitin_laad 
Thanks for your response. I have fixed the issue on my end.