Conversion of the outcome of a business rule task in the external task worker (node.js)

Hi all,

I followed the example of the website (https://docs.camunda.org/get-started/quick-start/service-task/#b-using-javascript-nodejs) and use node.ls as an external task worker.

Before the corresponding process (P2), I check a few rules in a business rule task using DMN (P1). As a result of P1 I get a list (Process P1 = Business Rule Task; Result Variable = “myOutput”, Map Decision Result = collectEntries).

In P2, a service task, I now want to use the result list from “myOutput” in an external task worker using node.js. In the Camunda Cockpit I can see that this variable is of type “Object”, the value is a “java.util.ArrayList” in Serialization Data Format = “application/x-java-serialized-object”.

Can someone explain how I can use this list in my external task worker? If I follow the example of the web page (const myOutput = task.variables.getTyped(‘myOutput’);), then I only get the serialized value of type “Object”. I don’t know how to deserialize it in node.js.

Since I haven’t found an entry elsewhere yet, the solution is probably obvious, but unfortunately I don’t see it.

Thank you for your help,
Oliver

P.S.: Note: If I only have a single value in the output of P1 (Map Decision Result = singleResult), I get the deserialized value directly and can work with it. Only in case of “Map Decision Result = collectEntries” I get a serialized object.

image

Hi,

you could simply set the default serialization format of the engine to JSON. Do it as described here for Spring Boot:

https://docs.camunda.org/manual/7.9/user-guide/spring-boot-integration/configuration/#camunda-engine-properties

or put that into your application server config:

{code:xml}

application/json

{code}

Of course, the serialization format can also be changed for each variable individually, but in your case that would imply to “rewrap” the result of the DMN execution (see https://docs.camunda.org/manual/7.9/user-guide/process-engine/variables/#object-value-serialization).

Best, Ragnar

Hi Ragnar,

Unfortunately I haven’t understood it yet, I think.

Does this mean that I can’t do the deserialization directly in node.js?

When calling the REST API, I can specify that the objects are delivered deserialized:

“deserializeValues”: true

Do I understand you correctly that I cannot do this with node.js and have to configure the deserialization in the server?

Maybe I didn’t get it right either.

I look forward to your hints.

Thank you
Oliver

Any further ideas?

Does anyone have another idea how I can enable deserialization in node.js?

OK, sometimes I need a little time to understand it.

But now and after a little research on defaultSerializationFormat I have made the appropriate property in the engine configuration (bpm-platform.xml) and now get my output values in JSON format.

Many thanks for the hint, Ragnar.

1 Like

@camORo hi , i have the same issue
i try to add those properties to bpm-platform.xml to be able to have only json not a serialized object

true
java.util.TreeMap

but everytime i add those properties to file , the engine refuse to start without any error
so how do you get json format ??
and here is a link to my issue : Deserialize map type in javascript

You can set a input parameter with the javascript code:

S(execution.getVariable("myOutput"),'application/json')

it serialize the java object and you can use it inside the node worker