Why is task not available in task output parameter script?

I am writing an output parameter script on a task. I expected to be able to reference task.assignee in my script. When I do that, I get:

groovy.lang.MissingPropertyException: No such property: task for class: Script2

I’d like to know why the task is not available in this context.

Hi @kgeis,

Could you please post the BPMN XML snippet of the task?

Cheers,
Thorben

Sure thing.

The intention is to set the assignee to hr_analyst_uid when the task is created, and if it is reassigned, then that process variable is set to the new assignee so that a subsequent task can be assigned to them.

<bpmn2:userTask id="ap_hr_preapproval" name="AP/HR Preapproval" camunda:formKey="ap_hr_preapproval" camunda:assignee="${hr_analyst_uid}" >
  <bpmn2:extensionElements>
    <camunda:formData>
<!-- deleted for brevity -->
    </camunda:formData>
    <camunda:inputOutput>
      <camunda:outputParameter name="hr_analyst_uid">
        <camunda:script scriptFormat="groovy">task.assignee</camunda:script>
      </camunda:outputParameter>
    </camunda:inputOutput>
  </bpmn2:extensionElements>
  <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
  <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
</bpmn2:userTask>

The output parameter is executed during the completion of the activity, at which point the task has been completed and deleted already. I suggest you use a task listener that listens for the assign or endcomplete event to set the variable.

Yes, I redid it as an assignment listener. Thank you for the explanation. That’s what I wanted most.

1 Like