Getting InputParameter variables of Task using Java API

How do we get inputParameter variable values using java code ?

  <cmmn:humanTask id="HumanTask_0xmmxjm" camunda:assignee="john" camunda:formKey="PatientDetails!f4370f84-4c53-423f-b28a-72573c2bfa14">
     <cmmn:extensionElements>
         <camunda:inputOutput>
           <camunda:inputParameter name="formArg">${formArg}</camunda:inputParameter>
           <camunda:outputParameter name="outcome" />
         </camunda:inputOutput>
     </cmmn:extensionElements>
  </cmmn:humanTask>

Hi @Suhas_Kulkarni, if you are trying to get the inputParameter from a JavaDelegate, you just need to call the method getVariable:

execution.getVariable(“formArg”);

but if not, you can get from the runtimeService

@Autowired private RuntimeService runtimeService;
@Autowired private TaskService taskService;

// get the task using the task Id
Task task = taskService.createTaskQuery().taskId(“your_task_id”).singleResult();

// get the execution using the execution Id
Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
execution.getVariable(“formArg”);

Thanks Kyle. Also Is there a camunda built in API that returns that?

I have case human task and used TaskCreationListener for reading variable -
execution.getVariable(“formArg”);

But I always get null value for above call. Any idea? JavaDelegate can only be attached to Service task and not human task right?

@Suhas_Kulkarni can you upload your model and in which activity you’re trying to access the form variables?

Below is my CMMN model with humanTask having inputParameter. I have process variable called “formArg” and it has value. but execution.getVariable(“payload”) is returning null. What can be issue?

<cmmn:humanTask id=“HumanTask_0xmmxjm” camunda:assignee=“ssaInstanceAdmin” camunda:formKey=“PatientDetails!f4370f84-4c53-423f-b28a-72573c2bfa14”>
cmmn:extensionElements
camunda:inputOutput
<camunda:inputParameter name=“payload”>${formArg}</camunda:inputParameter>
<camunda:outputParameter name=“outcome” />
</camunda:inputOutput>
<camunda:taskListener class=“com.oracle.process.approval.listener.dp.TaskCreationListener” event=“create” />
</cmmn:extensionElements>
</cmmn:humanTask>

variable is referenced in TaskCreationListener

Have you tried using Formservice in task Listener?

String taskId = delegateTask.getId();
FormService formService = delegateTask.getProcessEngineServices().getFormService();
TaskFormData taskFormData = formService.getTaskFormData(taskId);

Hi Arvind
TaskCreationListener attached to humanTask has access to DelegateCaseExecution
and I use delegateCaseExecution.getVariableLocal(“payload”). This returns null.
I was thinking “payload” inputParameter variable should have value assigned from ${formArg}.

I tried using formService that you mentioned but we use external forms and that really doesn’t fit and doesn’t work for me.

What I meant is I don’t get value of “x” variable in TaskCreationListener using execution.getVariable(“x”) for this input -
<camunda:inputParameter name=“x”>foo</camunda:inputParameter>

Refer this post,

Thanks Arvind

I still did not get value of InputParameter in TaskListener class . Here is my cmmn snippet -
<cmmn:humanTask name=“Provide Customer Rating” id=“HumanTask_2” camunda:assignee=“demo”>
cmmn:extensionElements
camunda:inputOutput
<camunda:inputParameter name=“x”>6</camunda:inputParameter>
<camunda:outputParameter name=“outcome” />
</camunda:inputOutput>
</cmmn:humanTask>

Here is my TaskListener implements TaskListener {
public void notify(DelegateTask delegateTask) {
DelegateCaseExecution execution = delegateTask.getCaseExecution();
String payload = (String) execution.getVariable(“x”); // returns null
payload = (String) execution.getVariableLocal(“x”); // returns null too.
}
}

Hi @kyle
I’m still not able to get inputParameter value in TaskListener (task create event). I can not use JavaDelegate as this is humanTask and not serviceTask. What am I doing wrong ?

Here is my cmmn snippet -
<cmmn:humanTask name=“Rating” id=“HT_2” camunda:assignee=“demo”>
.cmmn:extensionElements
.camunda:inputOutput
<camunda:inputParameter name=“x”>6</camunda:inputParameter>
</camunda:inputOutput>
</cmmn:extensionElements>
</cmmn:humanTask>

Here is my TaskListener implements TaskListener {
public void notify(DelegateTask delegateTask) {
DelegateCaseExecution execution = delegateTask.getCaseExecution();
String x = (String) execution.getVariable(“x”); // returns null
x = (String) execution.getVariableLocal(“x”); // returns null too.
x = runtimeService.getVariablesLocal(task.getExecutionId()); // throws error //execution does not exist
}
}

hi @Suhas_Kulkarni, I’m still newbie with CMMN, but is it possible to define inputParameter inside Human Task? Apparently camunda modeler doesn’t has this option

Thanks. Not sure if there is support for input/output for CMMN humanTask ?