CMMN - retrieving the form key using the form service

Hi Team,

I tried to read the formkey from a cmmn model using the form service.
Therefore I extended the loan-approval-cmmn getstarted project.

LifecycleListener:

  public void notify(DelegateCaseExecution caseExecution) throws Exception {
    LOGGER.info("Plan Item '" + caseExecution.getActivityId() + "' labeled '" + caseExecution.getActivityName() + "' has performed transition: "
        + caseExecution.getEventName());

    FormService formService = caseExecution.getProcessEngineServices().getFormService();
    String formKey = formService.getTaskFormData(caseExecution.getId()).getFormKey();
    LOGGER.info("FormKey '" + formKey + "'");
 }

loan-approval.cmmn11.xml:
<cmmn:humanTask isBlocking="true" name="Check Application" id="HumanTask_1" camunda:assignee="demo" camunda:formKey="formkey1">
<cmmn:extensionElements>
<camunda:caseExecutionListener event="create" class="org.camunda.bpm.getstarted.cmmn.loanapproval.LifecycleListener" />
</cmmn:extensionElements>
<cmmn:defaultControl>
<cmmn:manualActivationRule>
<cmmn:condition>${false}</cmmn:condition>
</cmmn:manualActivationRule>
</cmmn:defaultControl>
</cmmn:humanTask>

But during deploying following error will occured:
2016-08-24 15:08:11,863 ERROR [org.camunda.bpm.engine.context] (MSC service thread 1-4) ENGINE-16004 Exception while closing command context: No task found for taskId 'cf6502ac-69fb-11e6-abf2-34e6d7711437': task is null: org.camunda.bpm.engine.exception.NullValueException: No task found for taskId 'cf6502ac-69fb-11e6-abf2-34e6d7711437': task is null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_91] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_91] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_91] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [rt.jar:1.8.0_91] at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:334) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:49) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:44) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.cmd.GetTaskFormCmd.execute(GetTaskFormCmd.java:44) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.cmd.GetTaskFormCmd.execute(GetTaskFormCmd.java:32) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:58) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.engine.impl.FormServiceImpl.getTaskFormData(FormServiceImpl.java:62) [camunda-engine-7.5.4-ee.jar:7.5.4-ee] at org.camunda.bpm.getstarted.cmmn.loanapproval.LifecycleListener.notify(LifecycleListener.java:32) [classes:]

How can I get the cmmn formkey?
https://docs.camunda.org/manual/7.5/reference/cmmn11/tasks/human-task/

Thanks you for any suggestions.

Bernd

Hi Bernd,

For the method FormService#getTaskFormData you need to provide an id of an org.camunda.bpm.engine.task.Task instance. Note that such tasks are used in the context both BPMN and CMMN, and represent a unit of work a human has to perform. Accordingly, in CMMN a Task instance is created when a humanTask plan item reaches the ACTIVE state. You can find a Task via TaskService#createTaskQuery. The query has a filter by case execution id.

Cheers,
Thorben

Hi Thorben,

in my example the humanTask only had the ENABLE state. After changing the state to ACTIVE the formkey is received.

Thanks for your help.

Bernd