I have a model with a multi-instance subprocess, whose cardinality is set by a list that an user will populate through a form in a previous user task. This list corresponds to a list of projects. The subprocess is launched for each project, and what I want to do is, in the final user task, set an “approved” or “not approved”, and then push this particular project (which, in any given subprocess instance, will be in a “project” variable) to a “approvedProjects” list, in a global scope.
Ideally, since this is a very basic functionality, I don’t want to write an entire Java class, so I’ve been trying to get this done with scripting. The main problem I’m having is regarding serialization. With a groovy script task, I can fetch both the current project, and the global approvedProjects variables, but how can I, with groovy, add that project to the approvedProjects variable?
When I try this script:
project = execution.getVariable('project'); println project execution.getVariable('approvedProjects'); println approvedProjects approvedProjects.add(project); execution.setVariable('approvedProjects', approvedProjects);
I get this error:
An error happened while submitting the task form : Cannot submit task form bf835848-cd5a-11ed-95ef-7c8ae1e03c0e: Unable to evaluate script while executing activity 'Activity_1p1x1mu' in the process definition with id 'Process_0gy2g6n:1:99ab3b8f-cd5a-11ed-95ef-7c8ae1e03c0e': org.camunda.bpm.engine.ProcessEngineException: Cannot serialize object in variable 'approvedProjects': org.camunda.spin.impl.json.jackson.JacksonJsonNode
So, I’m assuming this should be fairly straightforward, only problem is how can I get around this serialization problem? What is the right way of fetching a list variable from the execution context, adding a value to it, and then set the variable back?
The projects list is created in a user task form, as a json object. The approvedProjects is created in a task’s output as an empty list. The project is pulled from the collection in the multi-instance subprocess, so I assume it’s also a JSON object (since the form creates a JSON list).