FileValue in ServiceTask of Element Template

Hello all,

currently i am working with the “element template” feature which i applied on a simple service task:
“appliesTo”: [“bpmn:ServiceTask” ],

One of the input variables is a FileValue which holds a pdf document in my case:

    {
          "label": "Document",
          "type": "String",
          "binding": {
            "type": "camunda:inputParameter",
            "name": "document"
          },
          "constraints": {
            "notEmpty": true
          }
        },

When i try to get the FileValue from execution within my service task:
FileValue document = (FileValue) execution.getVariableTyped("document");

i get something like this:
java.lang.ClassCastException: org.camunda.bpm.engine.variable.impl.value.PrimitiveTypeValueImpl$BytesValueImpl cannot be cast to org.camunda.bpm.engine.variable.value.FileValue

I did an extensive research but i had no luck finding a hint on how i can work with Files in my processes.
When working with FileValues in ServiceTasks (without using the Element Template) this problem did not occur.

Any ideas?

Ok solved it somehow.

I recognized in debug mode that when using Element Templates the DelegateExecution of my service task is of type “ScopeExecution[10]”. When using service tasks without Element Template it is of type “ProcessInstance[4]”.

The working solution is therefore to do the following:

DelegateExecution processInstance = scopeExecution.getProcessInstance();
FileValue document = (FileValue) processInstance.getVariableTyped(“document”);

The FileValue can now be used as expected.

MOEP. The “solution” is actually not working.

Well unless the process instance itself has a defined process variable named “document”.
The whole Input Mapping to a scope variable seems to break the FileValue.

I cannot believe that nobody ever tried using FileValues in combination with Element Templates?!
So what am i missing?