cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to execute supplied script: Couldn't serialize value 'org.mozilla.javascript.NativeArray

mtsiak
Star Contributor
Star Contributor

I am trying to set the users list that can execute a user task.
So, the user task is something like:

<userTask id="userTask1" name="Review" 
  activiti:assignee="${myflow_reviewassignee.properties.userName}"
  activiti:formKey="myflow:review">
    ...
    <multiInstanceLoopCharacteristics isSequential="false"
       activiti:collection="myflow_supervisors"
       activiti:elementVariable="myflow_reviewassignee">
        <completionCondition>${myflow_reviewapprovalcount != 0}</completionCondition>
      </multiInstanceLoopCharacteristics>
</userTask>

While in a previous serviceTask i am trying to set the user list 'supervisors'

var group = people.getGroup("GROUP_agroup");
var supervisors = people.getMembers(group);
execution.setVariable("myflow_supervisors", supervisors);
...

But i get the error

org.alfresco.scripts.ScriptException: 06040011 Failed to execute supplied script: 
Couldn't serialize value 'org.mozilla.javascript.NativeArray@28879284'
in variable 'myflow_supervisors'
Returning 500 status code

Any ideas?

Meanwhile, but for other workflows, if i add a rule on a folder, that starts a workflow when a user uploads a new documents, the workflow start with no errors.


var workflow = actions.create("start-workflow");
//...
var group = people.getGroup("GROUP_agroup");
workflow.parameters["mymodel:peoplelist"] = people.getMembers(group);
//...
workflow.execute(document);

Is there any difference between 'workflow.parameters' and 'execution.setVariable' ?

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

All the actions you create in JavaScript are handled specially with regards to JavaScript parameters as these JavaScript values are converted to proper Java instances before the actual execution. This means that using the parameters on the workflow action, a JavaScript array (NativeArray) will be converted into a Java List, and that is why it works. The "execution" object is a standard Activiti Java object without any special JavaScript integration layer, so any JavaScript value you try to set as a variable will not be converted to Java, and since Activiti does not know how to handle (most) JavaScript types, it fails with the exception that you have.

Most of the time, you cannot set any of the array-like values you can obtain from Alfresco root scope objects as variable values in Activiti without applying some mapping logic. I.e. you could create custom Java classes as extensions to the JavaScript API to map those values before you set them in the execution.

Of course you can always use the trick Krutik Jayswal‌ mentioned about converting the values to some stringified representation. Just be aware that you then would have to make sure you can also re-resolve the real values from the stringified representation when you need to, i.e. read the variables in another task / listener / delegate expression.

View answer in original post

3 REPLIES 3

krutik_jayswal
Elite Collaborator
Elite Collaborator

You can not do below in activiti.

execution.setVariable("myflow_supervisors", supervisors); 

Supervisors variable must be a serializable. Converting Supervisors to json string or coppma separated string of username will resolve the issue.Right now it is representing an association and that will create an issue.

I tryed to create a javascript array of objects with some properties from a node of a person (e.g. "username").

The task activity seemed to be created (for each canditate), and I did not get the "cannot serialize" error.

But when i browsed to the document's details (the one that was in the bpm_package.children of the workflow), error was printed: this time it could not deserialize an object.. supervisors. 

So I droped the idea. Thank you anyway. Fair try...

afaust
Legendary Innovator
Legendary Innovator

All the actions you create in JavaScript are handled specially with regards to JavaScript parameters as these JavaScript values are converted to proper Java instances before the actual execution. This means that using the parameters on the workflow action, a JavaScript array (NativeArray) will be converted into a Java List, and that is why it works. The "execution" object is a standard Activiti Java object without any special JavaScript integration layer, so any JavaScript value you try to set as a variable will not be converted to Java, and since Activiti does not know how to handle (most) JavaScript types, it fails with the exception that you have.

Most of the time, you cannot set any of the array-like values you can obtain from Alfresco root scope objects as variable values in Activiti without applying some mapping logic. I.e. you could create custom Java classes as extensions to the JavaScript API to map those values before you set them in the execution.

Of course you can always use the trick Krutik Jayswal‌ mentioned about converting the values to some stringified representation. Just be aware that you then would have to make sure you can also re-resolve the real values from the stringified representation when you need to, i.e. read the variables in another task / listener / delegate expression.