Troubleshooting JSON Parsing Error in Camunda User Task with Embedded HTML Form

I have a user task with an embedded HTML form. In the process, a JSON variable is set. However, it cannot be parsed as JSON.

I receive the following error in the Browser console:

SyntaxError: Unexpected token 'A', "Apple"... is not valid JSON
    at JSON.parse (<anonymous>)
    at Array.eval (eval at <anonymous> (camunda-tasklist-bootstrap.js?bust=7.20.0:2:1603), <anonymous>:15:31)
    at t.trigger (

Here is the script I am running:

<script cam-script type="text/form-script">

    camForm.on('variables-applied', function() {
        
        // Get the JSON data from the process variable
        var companysJSON = camForm.variableManager.variableValue('companys');

        // Parse the JSON data into a JavaScript array
        var companys = JSON.parse(companysJSON);

        // Iterate over the array and log each text in the console
        companys.forEach(function(company, index) {
            console.log('Company ' + (index + 1) + ': ' + company);
        });
    });
</script>

This is what my JSON variable looks like in the process:

I have the feeling that the retrieved value is no longer JSON but just a text string. I will be receiving longer texts instead of company names as in the example, where I need to correctly parse the JSON. (A JSON object, for example, can also contain a comma)

What am I doing wrong here?

1 Like

In the external forms we implement, we do not perform any parsing if the camunda variable we get from the variableManager via variableValue(). We use them the way we get them as JavaScript variables.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.