Error parsing Input/Output Variable Mappings

854 views
Skip to first unread message

michael...@gmail.com

unread,
May 15, 2015, 8:18:30 AM5/15/15
to camunda-...@googlegroups.com
I've setup a Service Task and used the rest http-connector to send the service task to PHP. We define a parameter called payload to send some data to the script and we can map it's output to a process variable with the response parameter.

This works fine for a simple payload like this:
${execution.id}

But we want to send a json, so we tried this:
{"id":"${execution.id}"}

This doesn't work, and the string is send without parsing. Actually, as soon as the line doesn't start with a $, it's not parsed. This should be improved.

id: ${execution.id}

also doesn't work.

We've found a workaround however:

${null}{"id":"${execution.id}"}

It seems that the parameter is only parsed when it starts with a $, IMO, this should be fixed and it should always be parsed.

Is this a bug? I've reported this as CAM-3893.

Sebastian Menski

unread,
May 18, 2015, 5:20:00 AM5/18/15
to camunda-...@googlegroups.com, michael...@gmail.com, michael...@gmail.com
Hi Michael,

if you would like to use mixed string/expression content you could use a script mapping with language Juel:

<camunda:inputParameter name="var2">
 
<camunda:script scriptFormat="Juel">{"id": "${execution.id}" }</camunda:script>
</camunda:inputParameter>

Could you give us feedback if this works for you?

Cheers,
Sebastian

michael...@gmail.com

unread,
May 18, 2015, 8:37:38 AM5/18/15
to camunda-...@googlegroups.com, michael...@gmail.com
Op maandag 18 mei 2015 11:20:00 UTC+2 schreef Sebastian Menski:
That seems to work also (with the CDATA tag), but is there any reason why it shouldn't work like this?

<camunda:inputParameter name="payload"><![CDATA[{"user":"${execution.id}"}]]></camunda:inputParameter>

Since this works fine:

<camunda:inputParameter name="payload"><![CDATA[${null}{"user":"${execution.id}"}]]></camunda:inputParameter>

The Juel-script seems like a clean way, but IMO it's also a workaround for the default way (where the payload is specified as Text).

Sebastian Menski

unread,
May 18, 2015, 9:44:11 AM5/18/15
to camunda-...@googlegroups.com, michael...@gmail.com, michael...@gmail.com
Hi Michael,

thanks for your feedback. Currently internally the engine distinguishes between static string values and expression. Whereas expression have to start
with "${" or "#{". This expression are than handled has Juel expressions and evaluated when needed. If the engine would treat every string as Juel
expression it could lead to unexpected behavior. If a string should be evaluated as an expression the user has to explicitly state that. Either mark
it as expression by starting with "${" resp. "#{" or by explicitly using a Juel script.

Also if you want to create more or less complex request bodies it may be interesting to use templating [1]. Or extract the request body from the 
bpmn file and use an external resource as script [2].

I will close the CAM-3893 ticket, as we cannot change the default behavior, and as there is a simple solution for this use case. Hope that is okay
for you.

Cheers,
Sebastian

michael...@gmail.com

unread,
May 18, 2015, 11:01:42 AM5/18/15
to camunda-...@googlegroups.com, michael...@gmail.com
Op maandag 18 mei 2015 15:44:11 UTC+2 schreef Sebastian Menski:
Thanks for the information, we will use the scriptFormat="Juel" method.
Reply all
Reply to author
Forward
0 new messages