AnsweredAssumed Answered

Exception on fetching process with non-completed startup form

Question asked by mteira on Sep 7, 2018

Hello all,

I'm facing a problem with Activiti 6.0.0 when a BPMN process with a defined start form (start event with activiti:formKey defined) is started programatically using the engine runtimeService like this:

 

runtimeService.startProcessInstanceByKey(settings.getIdentificationWorkflowKey(),
                        Collections.singletonMap("deviceSerialNumber",  "mySerialNumber"));

 

The process starts normally and runs into an User Task. When I try to use activiti-ui to claim and process the task, an internal error gets thrown:

 

Caused by: org.activiti.form.engine.ActivitiFormException: No submitted form could be found
        at org.activiti.form.engine.impl.cmd.GetCompletedFormDefinitionCmd.resolveSubmittedForm(GetCompletedFormDefinitionCmd.java:222)
        at org.activiti.form.engine.impl.cmd.GetCompletedFormDefinitionCmd.execute(GetCompletedFormDefinitionCmd.java:87)
        at org.activiti.form.engine.impl.cmd.GetCompletedFormDefinitionCmd.execute(GetCompletedFormDefinitionCmd.java:49)
        at org.activiti.form.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:29)
        at org.activiti.form.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:56)
        at org.activiti.form.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:35)
        at org.activiti.form.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:39)
        at org.activiti.form.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:34)
        at org.activiti.form.engine.impl.FormServiceImpl.getCompletedTaskFormDefinitionByKeyAndParentDeploymentId(FormServiceImpl.java:107)

       at org.activiti.app.rest.runtime.AbstractProcessInstanceResource.getStartFormDefinition(AbstractProcessInstanceResource.java:146)
        at org.activiti.app.rest.runtime.AbstractProcessInstanceResource.getProcessInstance(AbstractProcessInstanceResource.java:90)
        at org.activiti.app.rest.runtime.ProcessInstanceResource.getProcessInstance(ProcessInstanceResource.java:34)

The problem seems to be related to the fact that ProcessInstanceResource.getProcessInstance assumes that when the start event has a formKey defined, it must have been started by means of the start form, and therefore it tries to fetch it. In org.activiti.app.rest.runtime.AbstractProcessInstanceResource, we can find:

 

  protected FormDefinition getStartFormDefinition(String processDefinitionId, ProcessDefinitionEntity processDefinition, String processInstanceId) {
    FormDefinition formDefinition = null;
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
    Process process = bpmnModel.getProcessById(processDefinition.getKey());
    FlowElement startElement = process.getInitialFlowElement();
    if (startElement instanceof StartEvent) {
      StartEvent startEvent = (StartEvent) startElement;
      if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
        formDefinition = formService.getCompletedTaskFormDefinitionByKeyAndParentDeploymentId(startEvent.getFormKey(),
            processDefinition.getDeploymentId(), null, processInstanceId, null, processDefinition.getTenantId());
      }
    }

    return formDefinition;
  }

My question is if this is a valid assumption. In my use case, I normally start the process programatically but I also want to be able to start using activiti-ui by filling up values in a form.

 

- Should the engine assume that a running process instance must always have a completed startup form if they process definition has a formKey in the start element?

- In case it should, what is the recommended way to achieve what I'm trying to do here? (A process that can be started either programatically or by using a form).

 

Thanks and best regards,

Manuel

Outcomes