ScriptTask: Unable save javascript json object as variable

Hi,
I’m trying to run a javascript code using the script task. We are using the secure javascript module.
The script we are trying to execute is

var batchExport = {};
batchExport.exportProfile = "testProfile"; 
batchExport.batchName = "rrrrrr";

execution.setVariable("aaa",batchExport);

When we are trying to execute this getting error like,

org.flowable.common.engine.api.FlowableException: Couldn't serialize value '[object Object]'

Can someone help on how to resolve this.

Thanks…

One way to work around this is as follows:
execution.setVariable(“aaa”,JSON.stringify(batchExport));

var batchExport = JSON.parse(execution.getVariable(“aaa”));

1 Like

Hi @maudrid,
Thanks for the workaround.
But i feel like there is should be some native support for this.

The problem is not with flowable.
Java does not know how to serialise a javascript object.

Hi,
I never said the problem is with flowable. I just expressed that it would be helpful if flowable had some kind of support to handle the javascript json objects.
We are using the secure javascript until and so the rhino engine is at the background running the scripts.
As I understand, rhino parses the javascript objects inside the instance of a NativeObject. NativeObject by itself is Serializable(from doc). But because of some flowable secure javascript scope object reference, the serialization is failing. In this case it kind of seems a problem on the flowable end.
I’m sorry if I got anything wrong.

Thanks.

Hi @vamshichanda We are facing similar issue. Below issue

  1. We are using SecureScriptExecutor for whitelisting java classes.
  2. While trying to access a field of json variable in script task, we are getting undefined. Somehow rhino engine unable to execute variable having json type.
    var student = execution.getVariable(“student”)//Here student is json type
    execution.setVariable(“student_name”, student.name);//Here student_name is becoming undefined as rhino engine is unable to process json variable.