Bonita 6.3.3 - Update LIST Variable from groovy

Hi there,

I’m still relatively new to Bonita level coding and am trying to use the code example here to populate a LIST variable from Groovy Script but with no success…it’s using code I don’t know…

I don’t know how to use UUID query runtime etc. and keep getting an error.

So as a full code example…can you show me how it’s done…

I know how to do single Strings that’s here, and I’ve tried that with no success…the code will be executed several times during a process so need to know the step it’s on to fill the variable. I think this code only works at process level, i need it at step level…

import org.bonitasoft.engine.api.ProcessRuntimeAPI;

ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
String processName = processRuntimeAPI.getProcessInstance(processInstanceId).getName();

List l1 = new ArrayList();
l1.add(“text1”);
l1.add(“text3”);
l1.add(“text2”);

apiAccessor.getProcessAPI().updateProcessDataInstance(
“definedListVar”,
processInstanceId,
l1);

Many thanks for your help in advance,

best regards
Seán

Hi,
The example you are looking is for the version 5.X of Bonita. UUID doesn’t work with 6.X.
To populate a list with some from a groovy script, you can use a Script Task.
In the Operations tab of this task, you put your variable in the left, and in the right member you create a script.
You can use this script :

List l1 = new ArrayList();
l1.add(“text1”);
l1.add(“text3”);
l1.add(“text2”);
return l1;

Thanks Yannick,

BUT, I don’t want to return the list - I want to SET the List Variable…they are two different things…

Similar to the code I showed which updates a variable direct without a return.

apiAccessor.getProcessAPI().updateProcessDataInstance("thisIsMyVar", processInstanceId, "This is the data");

thanks

What I said is to SET a variable. Your variable take the value that is returned by the script.

Ok, sorry, but still not what I want,

This is what I want to do…

this occurs multiple times per process

Step → On-enter
Connector to fill list - groovy - set list variable with “a1”, “a2”, “a3” (non-changable by customer)
Connector to retrieve data based on List (returns a new ListOut) - java - get x where col1 = a1 etc…

Step → Display
display the returned ListOut for text/data to be shown in fields “a1”, “a2”, “a3”

The data “a1”, “a2”, “a3” can be a-z and 1-100 depending on page…

I know another way to do it but…it means a lot of redesign and rework, and “a-z and 1-100” calls to groovy…urgh…

the 5 version I showed, examples what I want it to do…but how do I do it in 6?

Thanks and regards
Seán