Use javascript script to modify list (camunda 7) `Cannot find serializer for value 'Untyped value '[]', isTransient = false'.`

Hello,

I am using camunda 7.19. I’ve created small BPMN which has a process variable listValue

I would like to use js to modify the values of the list

the script is

function getNumber(){
    var number = execution.getVariable('number')
    print("found number " + number);
    
    var listValues = execution.getVariable('listValues');
    for (var i=0; i<listValues.length; i++)
        print(i + ". " + listValues[i]);

    const newList = [];
    execution.setVariable('listValues', newList);
}

getNumber()

I’ve added GraalVM Js to use this in the tests

        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>21.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>21.1.0</version>
        </dependency>

the js script is called and I am able to read the values but the setVariable fails with Cannot find serializer for value 'Untyped value '[]', isTransient = false'.

I have checked and listValues is an array (with Array.isArray) but it doesn’t have the methods I would expect from an array (e.g. push).

Question: how do you manipulate the BPMN list variables in javascript?

do I have to use “Camunda Spin”?

Hello my friend \o

Yes, Camunda SpinJson “S()” would help you to solve your problem.
Look for Spin’s S() method.

Below JavaDoc SpinJsonNode:

https://javadoc.io/doc/org.camunda.spin/camunda-spin-core/1.5.6/org/camunda/spin/json/SpinJsonNode.html

I hope this helps!
:smiley:

William Robert Alves