Highlighted

Can I apply workflow for approval of editable template that author is going to enable.

Avatar

Avatar

akashdhawle

Avatar

akashdhawle

akashdhawle

27-06-2019

I have a scenario like after creation of editable template, When author is going to enable it then only after approval that template should get enabled for creating pages. Can you please suggest me the approach if this is possible. 

Replies

Highlighted

Avatar

Avatar

antoniom5495929

Avatar

antoniom5495929

antoniom5495929

28-06-2019

Hi,

I think you can do it just by customizing the view.

You can:

- customize the enable button by createing in apps the same of /libs/wcm/core/content/sites/templates/jcr:content/actions/selection/enabletemplate, in order to make a call to your servlet with run a workflow instance of your workflow model of approval

- if the changes are approved, into a custom workflow step you can set the status to enabled in template path ( e.g. /conf/we-retail/settings/wcm/templates/mytemplate/jcr:content)

Let me know if you need more info.

Thanks,

Antonio

Highlighted

Avatar

Avatar

akashdhawle

Avatar

akashdhawle

akashdhawle

28-06-2019

Hi Antonio,

Thank you for the reply.

1. As, Enable option is present default in the tool,  how should I make it customized through apps. (for giving servlet call to run workflow)

2. Is there any way by which I can get the current template(which is to be enabled) path in servlet so that I can pass it to the workflow.

Thanks,

Akash 

Highlighted

Avatar

Avatar

antoniom5495929

Avatar

antoniom5495929

antoniom5495929

28-06-2019

Hi Akash,

By points:

1. You just need to go into the path, right click and select "Overlay Node..." this is the standard approach used in order to customize some elements in AEM. After overlay this node, you have multiple choice:

  1. Create a new actions property to send data in a custom servlet
  2. Remove the action property and use a javascript loaded into cq.authoring categories in order to attach an event to your button and make the ajax by sending also selected template as parameter

2. Into your servlet you need to run an instace of your custom model by using the following snippet and based on a payload which need to be the path of your template

ResourceResolver resourceResolver = null;

try {

  resourceResolver = ResourceUtils.getResourceResolver(resourceResolverFactory);

   session = resourceResolver.adaptTo(Session.class);

  WorkflowSession wfSession = workflowService.getWorkflowSession(session);

  WorkflowModel wfModel = wfSession.getModel(workflowName);

  WorkflowData wfData = wfSession.newWorkflowData(JCR_PATH_WF_PROPERTY, workflowContent);

  wfSession.startWorkflow(wfModel, wfData);

   return SC_ACCEPTED;

} catch (WorkflowException e) {

   LOGGER.error(e.getMessage(), e);

}

return SC_INTERNAL_SERVER_ERROR;

Let me know.

Thanks,

Antonio