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

debugging the workflow

Avatar

Level 7

I am creating a simple workflow which would e able to create sonme node inside /cotent when i trigger that workflow.

I created a process step (a service ) and added that steps in my workflow and saved .

no new node has been created inside my /content.

code is like that :

=============

package amitsample.core.filters;

import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.framework.Constants;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import java.util.HashMap;
import java.util.Map;
@Component

@Service

@Properties({

   @Property(name = Constants.SERVICE_DESCRIPTION, value = "Sample Workflow Process implementation amit"),

   @Property(name = "process.label", value = "my first workflow process step") ,

   @Property(name = "service.pid",value = "amitsample.core.filters.WorkflowSamplefilter")

})

public class WorkflowSamplefilter implements WorkflowProcess {

   @Reference
   ResourceResolverFactory resourceResolverFactory;

   @Override
   public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {

  Map<String, Object> usermap = new HashMap<String, Object>();
   usermap.put(ResourceResolverFactory.SUBSERVICE,"kuchbhi");
   ResourceResolver resourceResolver = null;
  try {

  resourceResolver = resourceResolverFactory.getServiceResourceResolver(usermap);
   } catch (LoginException e) {

  e.printStackTrace();
   }

  String nodepath="/content/amitsample";
   Session session=resourceResolver.adaptTo(Session.class);

   Node planetNodeList= resourceResolver.getResource(nodepath).adaptTo(Node.class);

   Node planetNameListNode = null;
  try {

  planetNameListNode = planetNodeList.addNode("testingworkflow1", "cq:Page");
   Node planetNameListJcrNode= null;
   planetNameListJcrNode = planetNameListNode.addNode(Node.JCR_CONTENT, NodeType.NT_UNSTRUCTURED);
   planetNameListJcrNode.setProperty(javax.jcr.Property.JCR_TITLE,"testingworkflow_title");
   session.save();
   } catch (RepositoryException e) {

  e.printStackTrace();
   }

  }

}

==============================

1835930_pastedImage_9.png

Any idea how I can debug my workflow ?

1 Accepted Solution

Avatar

Correct answer by
Level 3

AdobeID24​, Please check the workflow model, if the "Handler Advance" is checked in the before step. That should be checked-in, else it will not move to the next step. If it is checked-in and still not going to the next step, please check the error logs once

What is your actual requirement, if it is only simply page creations or node creations you can always use some standalone scripts to create the hierarchy, if it is like creating a different node based on some action, workflow is fine.

You can find a couple of standalone scripts here

View solution in original post

6 Replies

Avatar

Employee Advisor

Add some DEBUG statements to the code and then setup a DEBUG logger on the following classes:

com.adobe.granite.workflow

com.day.cq.workflow

amitsample.core

This will provide the backend details on whats happening.

Avatar

Employee Advisor

Check your console for exceptions (unfortunately you use e.printStackTrace() instead of proper logging).

Jörg

Avatar

Level 7

I did not get any entry in any of those log files ...I m still confused my workflow is ruunning or not because action which i wrote inside execute methodis not happening but when i check instance i can see my workflow instance is ruuning.

Avatar

Level 7

1836038_pastedImage_0.png

It seems my workflow is not going to 2nd step which is process step? is that so ?

Avatar

Correct answer by
Level 3

AdobeID24​, Please check the workflow model, if the "Handler Advance" is checked in the before step. That should be checked-in, else it will not move to the next step. If it is checked-in and still not going to the next step, please check the error logs once

What is your actual requirement, if it is only simply page creations or node creations you can always use some standalone scripts to create the hierarchy, if it is like creating a different node based on some action, workflow is fine.

You can find a couple of standalone scripts here

Avatar

Employee

I would suggest you to check ths following doc where you can see how to create a workflow, invoke it, and monitor it.

Adobe Experience Manager Help | Using Adobe Experience Manager Workflows