AnsweredAssumed Answered

Starting of workflow through the java

Question asked by kranthi on Mar 29, 2017
Latest reply on Aug 11, 2017 by kranthi

Actually I am trying to start the workflow through the java within the service task of another workflow.Here I just wanted to start the out of the box workflow but I am getting null pointer exception even I am passing all variable.

Here am adding java code please go through it.

 

public class ReviewStrtingwf extends DelegateExecutionScriptBase implements ExecutionListener,JavaDelegate{

public static final Logger logger = Logger.getLogger(ReviewStrtingwf.class);
private static final String GROUP_NAME = "REVIEWERS";
private static final String WORKFLOW_DESCRIPTION = "Request for approval";
private static final String TASK_DESCRIPTION = "Check contents and review.";
private static final String ACTIVITI_PARALLEL_GROUP_REVIEW_NAME = "activiti$activitiParallelGroupReview";

@Override
public void notify(DelegateExecution exe) throws Exception {
// TODO Auto-generated method stub

NodeService nodeservice = getServiceRegistry().getNodeService();
WorkflowService workflowService = getServiceRegistry().getWorkflowService();
AuthorityService authorityService=getServiceRegistry().getAuthorityService();
NodeRef pkgRef = ((ActivitiScriptNode)exe.getVariable("bpm_package")).getNodeRef();
logger.debug("pkgRef:"+pkgRef);
List<ChildAssociationRef> childs = nodeservice.getChildAssocs(pkgRef);
for(ChildAssociationRef child:childs){
NodeRef node = child.getChildRef();
logger.debug("node:"+node+"\n");

String resubmitationoutcome= (String) exe.getVariable("awfSubmitOutcome");
logger.debug("resubmitationoutcome:"+resubmitationoutcome+"\n"+"docname:"+nodeservice.getProperty(node, ContentModel.PROP_NAME));
try{
if(resubmitationoutcome !=null && resubmitationoutcome.equals("Submit"))
{
logger.debug("sdsdsdsds");
NodeRef workflowNodeRef = workflowService.createPackage(null);
logger.debug("workflowNodeRef:"+workflowNodeRef);
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
logger.debug("parameters:"+parameters);
parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowNodeRef);
logger.debug("1");
parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, WORKFLOW_DESCRIPTION);
logger.debug("WORKFLOW_DESCRIPTION:"+WORKFLOW_DESCRIPTION);
parameters.put(WorkflowModel.PROP_DESCRIPTION, TASK_DESCRIPTION);
logger.debug("TASK_DESCRIPTION:"+TASK_DESCRIPTION);
logger.debug("reviewers:"+authorityService.getAuthorityNodeRef("GROUP_" + GROUP_NAME));
parameters.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE,
authorityService.getAuthorityNodeRef("GROUP_" + GROUP_NAME));
logger.debug("2");
parameters.put(WorkflowModel.PROP_PERCENT_COMPLETE, 50);
logger.debug("3");
// Add zero or more items
nodeservice.addChild(
workflowNodeRef,
node,
WorkflowModel.ASSOC_PACKAGE_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName(nodeservice.getProperty(
node, ContentModel.PROP_NAME).toString())));
logger.debug("4");
WorkflowDefinition wfDefinition =
workflowService.getDefinitionByName(ACTIVITI_PARALLEL_GROUP_REVIEW_NAME);
logger.debug("5");
workflowService.startWorkflow(wfDefinition.getId(), parameters);
logger.debug("6");
}
}
catch( RuntimeException err)
{
logger.debug("error:"+err);
throw err;
}
catch( Exception err)
{
logger.debug("errors123:"+err);
err.printStackTrace();
}
}
logger.debug("workflow started on document");
}

Outcomes