How to inject values to servicetasks: field/inputParameter

When using “camunda:modelerTemplate” in the modeller, we obtain this bpmn snippet:

<bpmn:sendTask camunda:class="gdp.servicetasks.EmailTaskService" camunda:modelerTemplate="cat.dipta.actio.MailTask" completionQuantity="1" id="email" implementation="##WebService" isForCompensation="false" name="Email" startQuantity="1"><bpmn:extensionElements><camunda:inputOutput><camunda:inputParameter name="subject">message for ${user}</camunda:inputParameter>[...]

According to documentation (camunda docs), the contents of camunda:inputParameter should be evaluated and available to class gdp.servicetasks.EmailTaskService

In our JavaDelegate class, we have:

    public void execute(DelegateExecution ex) throws Exception {
        println "SBJ: ${ex.getVariable('subject')}"

And we expected to get “SBJ: message for mabertran” because value of variable ‘user’ is mabertran.
Instead of this, we get the original “SBJ: message for ${user}” string.

We tried to declare field
Expression subject
And get the value by subject.getValue(ex) but didn’t work.

The only way we could reach the desired result was by changing our bpmn:
<camunda:inputParameter name="subject"> <camunda:script scriptFormat="groovy">"message for ${user}"</camunda:script></camunda:inputParameter>

And then ${ex.getVariable('subject')} made the evaluation of such script which evaluates to the desired string, but I’d like to avoid this solution because I don’t like to evaluate a variable (which my be assigned by a user) as a groovy script.

FINALLY:

Is a way to use <camunda:inputParameter> in a similar as <camunda:field> to evaluate expressions (described here)?

Which is the best solution to use field injection in combination with camunda:modelerTemplate which seems to force the use of <camunda:inputParameter>?

UPDATE:

We tried <camunda:inputParameter> with a content that is uniquely an expression (only content like: ${expression} and nothing else) and expression evaluation finally seems to work as expected. The only thing is that I need to evaluate something of the form: "message sent to ${user}"

At last, the best option seems to be to use <camunda:field><camunda:expression>CONTENT ${with some expression}</camunda:expression></camunda:field>.

Anyway, I wonder if it would be a good idea to make camunda:field and camunda:inputParameter to work in the same way, or are we are missing some point and they must be kept working as they do? In such case, some more detailed documentation might be need about what makes them different and what should each one be used for.

Hi @mabertran,

currently, the camunda modeler doesn’t support fields (see the issue).

I think you can also pass the input using one expression:

<camunda:inputParameter name="subject">
  ${'message for '.concat(user)}
</camunda:inputParameter>

I know this is not the best way but works. If you want to have fields for templates, you can vote for the issue :wink:

Best regards,
Philipp

1 Like

Good point, even we will keep using camunda:field for the moment as we do not use this directly in the modeler but in a post-process of a given model.

By the way, I’d really find interesting to know the difference between camunda:field and camunda:inputParameter for a task. Can anybody point to some meaningful documentation about this issue?

Hi @mabertran,

you can use fields and input parameters in the same way. The only difference is that an input parameter is stored in the history since it is a variable.

Best regards,
Philipp

Thanks for your answer. That’s been very useful!