Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Content approval gets triggered on publish

Avatar

Level 2

requirement is to when user click on publish, in rail.The  page should be moved to workflow and then gets activated from there only if condition is met. 
Tried listener which listens to event activation and trigger workflow. But it seems the page is already getting activated. Need help on this.
User already have access to publish assets/page.

Topics

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

6 Replies

Avatar

Level 3

Hi @Abhijeet_Kumar ,
In such case, you should make use of AEM's OOTB Request for Activation or Request for Deactivation workflows. But first you need to manage ACLs of content authors and remove their publishing access. You can follow the following article to see how to trigger a customized workflow: AEM - Trigger customized workflow on manage publication. (bimmisoi.blogspot.com)

 

-Vikas Chaudhary

Avatar

Level 2

Hi @VikasChaudhary_  The requirement is not to remove ACLs and yet trigger workflow on click of publish.Is there any way to achieve this? 
Thanks.

Avatar

Community Advisor

Hi @Abhijeet_Kumar 

1.Create a workflow model that includes the necessary steps to validate the condition and activate the page if the condition is met. You can use the Workflow Modeler in AEM to create the workflow model.

2.Associate the workflow model with the page's blueprint or template. This can be done by adding the cq:workflowModel property to the blueprint or template node in the repository.

3.Create a custom event listener that listens for the beforeActivate event and triggers the workflow if the condition is met. Here's an example of how the listener code might look:

@Component(service = EventListener.class,
           property = {
               EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC
           })
public class MyReplicationListener implements EventListener {

    @Reference
    private WorkflowService workflowService;

    @Override
    public void handleEvent(Event event) {
        ReplicationAction action = ReplicationAction.fromEvent(event);
        if (action.getType() == ReplicationActionType.ACTIVATE) {
            Resource resource = action.getPath();
            if (resource != null && resource.adaptTo(Page.class) != null) {
                Page page = resource.adaptTo(Page.class);
                if (shouldTriggerWorkflow(page)) {
                    triggerWorkflow(page);
                }
            }
        }
    }

    private boolean shouldTriggerWorkflow(Page page) {
        // Check if the condition is met
        return true;
    }

    private void triggerWorkflow(Page page) {
        // Start the workflow
        WorkflowData workflowData = new WorkflowData(page.getPath(), null);
        WorkflowStartOptions options = new WorkflowStartOptions();
        options.setWorkflowModel("/etc/workflow/models/myworkflow");
        workflowService.startWorkflow(options, workflowData);
    }

}

4.Deploy the listener code to your AEM instance and register it as an OSGi service.

5.When a user clicks the Publish button, the page will be moved to the workflow and the before Activate event will be triggered. If the condition is met, the workflow will be started and the page will be activated from the workflow. If the condition is not met, the page will remain in the workflow and will not be activated.



Avatar

Level 2

I am looking for the event which is triggered before Activate. replicationAction event is triggered post replication of assets.

Avatar

Community Advisor

Hi @Abhijeet_Kumar 
You can add a new button e.g.' content publish' and trigger a custom workflow.



Arun Patidar