cancel
Showing results for 
Search instead for 
Did you mean: 

activitiUtil.getProcessInstance(instanceId) returns null

tullo1
Champ in-the-making
Champ in-the-making
Hi

I try to start the ootb adhoc workflow from within a service task in alfresco.

When the service task is triggered the method call activitiUtil.getProcessInstance(instanceId) will always return null for an instanceId mapped to the adhoc worflow just started. 

ActivitiTypeConverter

public WorkflowPath convert(Execution execution)
{
    String instanceId = execution.getProcessInstanceId();
    ProcessInstance instance = activitiUtil.getProcessInstance(instanceId);
    return convert(execution, instance);
}


Could that be a transaction related problem?

BR
Andreas
13 REPLIES 13

tullo1
Champ in-the-making
Champ in-the-making
This is what gets executed:
<code>
public ProcessInstance getProcessInstance(String id)
{
  return runtimeService.createProcessInstanceQuery()
    .processInstanceId(id)
    .singleResult();
}
</code>

tullo1
Champ in-the-making
Champ in-the-making
And here is the code that creates the workflow
<code>
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
    final Object bpm_package = delegateExecution.getVariable("bpm_package");
    if (bpm_package instanceof ActivitiScriptNode) {
        ActivitiScriptNode asn = (ActivitiScriptNode) bpm_package;
        final NativeArray children = (NativeArray) asn.getChildren();
        for (int i = 0; i < children.getLength(); i++) {

            final ScriptNode node = (ScriptNode) children.get(i, children);

            Map<QName, Serializable> params = new HashMap<QName, Serializable>();
            params.put(WorkflowModel.PROP_DESCRIPTION, node.getName() + " needs to be reviewed again");
            Date dueDate = Calendar.getInstance().getTime();
            params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
            params.put(WorkflowModel.PROP_PRIORITY, 3);

            final Object obj = delegateExecution.getVariables().get("initiator");
            if(obj != null) {
                ActivitiScriptNode person = (ActivitiScriptNode) obj;
                // triggers property fetching via NodeService
                person.getProperties();
                QName QNAME_INITIATOR = QName.createQName(NamespaceService.DEFAULT_URI, WorkflowConstants.PROP_INITIATOR);
                params.put(QNAME_INITIATOR, person);
                params.put(WorkflowModel.ASSOC_ASSIGNEE, person);
            }

            final NodeRef workflowPackage = getServiceRegistry().getWorkflowService().createPackage(null);
            params.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
            getServiceRegistry().getNodeService().addChild(workflowPackage, node.getNodeRef(),
                    WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
                    QName.createValidLocalName((String) getServiceRegistry().getNodeService().getProperty(node.getNodeRef(), ContentModel.PROP_NAME))));
            final WorkflowDefinition adhocDef = getServiceRegistry().getWorkflowService().getDefinitionByName("activiti$activitiAdhoc");
            final WorkflowPath adhoc = getServiceRegistry().getWorkflowService().startWorkflow(adhocDef.getId(), params);

            if (log.isDebugEnabled())
                log.debug("###created ad-hoc notify workflow for node " + node.getName());
        }
    }
}
</code>

trademak
Star Contributor
Star Contributor
What's the value of "final WorkflowPath adhoc"?
Is the process instance started correctly?
At what point are you executing the get process instance logic?

Best regards,

tullo1
Champ in-the-making
Champ in-the-making
The execution does not make it that far as the NPE is thrown in the startWorkflow method which also calls the get process instance logic.

23:32:51,804 DEBUG [org.activiti.engine.impl.interceptor.LogInterceptor] — starting GetUnlockedTimersByDuedateCmd ——————————————————–
23:32:51,805 DEBUG [org.activiti.engine.impl.db.DbSqlSession] flush summary: 0 insert, 0 update, 0 delete.
23:32:51,805 DEBUG [org.activiti.engine.impl.db.DbSqlSession] now executing flush…
23:32:51,805 DEBUG [org.activiti.engine.impl.interceptor.LogInterceptor] — GetUnlockedTimersByDuedateCmd finished ——————————————————–
23:32:51,805 DEBUG [org.activiti.engine.impl.interceptor.LogInterceptor]                                                                                                    
23:32:51,805 DEBUG [org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable] job acquisition thread sleeping for 5000 millis
23:32:51,806 DEBUG [org.activiti.engine.impl.interceptor.CommandContext] Error while closing command context
java.lang.NullPointerException
at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:300)
at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:280)
at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.startWorkflow(ActivitiWorkflowEngine.java:995)
at org.alfresco.repo.workflow.WorkflowServiceImpl.startWorkflow(WorkflowServiceImpl.java:438)
….
stack trace can be found in the attached log file

debug screenshots http://ctrlv.in/261316 http://ctrlv.in/261320 http://ctrlv.in/261323

tullo1
Champ in-the-making
Champ in-the-making
I still need help with this issue, so any input is welcome!

And if it's a transaction thing, how can I solve that part of the problem?

trademak
Star Contributor
Star Contributor
So if I understand it correctly, you have a service task in your process definition that tries to get its own process instance entity?
Because the process instance is not stored yet at that moment that's not possible. You could make the service task asynchronous to resolve this. But why do you need the process instance entity reference?

Best regards,

tullo1
Champ in-the-making
Champ in-the-making
Not quite, I just show debugging info I was asked about further up.

What I want to do is to create new ad-hoc workflows for all the documents in the bpm_package when the task owner pushes the "For Revision" button and triggers the transitions to the service task. The result of that is the NPE shown here http://ctrlv.in/261323
1. In the service task I loop over the children in the bpm_package and try to create new ad-hoc workflows for all of them
2. The call to the startWorkflow method always results into the NPE http://ctrlv.in/261320
3. The debuging session shows that the NPE happens in the Activity engine code (Alfresco flavor) http://ctrlv.in/261316

Regards,
Andreas

frederikherema1
Star Contributor
Star Contributor
Do the started ad-hoc workflow have any user-tasks or receive-tasks in them? Or are you talking about the out-of-the-box adhoc-workflow. this can explain the NPE in some cases.

Anyhow, it's not the best of ideas to start workflows from within activiti-delegates, using the WorkflowService. Have you looked at a multi-instance call-activity?

tullo1
Champ in-the-making
Champ in-the-making
Exactly, it is the ootb alfresco adhoc workflow I am talking about. I'll try the call-activity and see if that can do the trick.

Regards, Andreas