Update MultiList value in Groovy

The Oracle documentation might work for Java, but I am trying to do this in a Groovy script process extension.  How do I write the setSelection statement?

// Trying this in a Groovy script in Agile
// Want to add 3 values to a MultiList field.
private void mrmtest(IBaseScriptObj obj, IItem mitem) throws APIException {

String abValue = (String) mitem.getValue(ItemConstants.ATT_PAGE_TWO_MULTILIST03);
String[] strArr = abValue.split(“;”);

ArrayList<String> ablist = new ArrayList<String>();

for (String temp : strArr) {

if ( ablist.contains(“Green”) == false ) { ablist.add(“Green”); }
if ( ablist.contains(“Blue”) == false ) { ablist.add(“Ble”); }
if ( ablist.contains(“Purple”) == false ) { ablist.add(“Purple”); }

if(null != ablist && !ablist.isEmpty()) {
int valuesListSize = ablist.size();

ICell stmcell = mitem.getCell(ItemConstants.ATT_PAGE_TWO_MULTILIST03);
IAgileList stmvalues = stmcell.getAvailableValues();

wrmStr = ablist.toString();

// —  This next line is where it won’t compile and I get the error. How do I do setSelection in Groovy?

stmvalues.setSelection(new Object[] wrmStr);

// stmcell.setValue(stmvalues);

Agile Talent Asked on February 11, 2021 in Software Development Kit (API).
Add Comment
1 Answer(s)

I wanted to give an update here, now that I have more or less solved my issue.
The MultiList03 attribute on the item is configured in our system to use a list.
And the list it uses is the Agile ‘User Groups’ list, which is considered a dynamic list.
A simple list is easier to deal with. Let’s say I have a User Group named “Texas”, and another named “Arizona”.
Below is an example of some code that shows how I can replace the current values, with “Texas” and “Arizona”.
This is Groovy code added to the code section of an Event Handler within Agile PLM 936.

// MultiList03 uses the ‘User Groups’ list, which is a dynamic list in Agile, not a simple list
// item is of the type IItem, which we already defined before getting to this point

ICell cell = item.getCell(CommonConstants.ATT_PAGE_TWO_MULTILIST03);
IAgileList values = cell.getAvailableValues();
if (values.getChildNodes() == null) {
IAgileClass cls = cell.getAttribute().getListAgileClass();
obj.logMonitor(“cls: ” + cls); // <– output is — cls: User Groups
if (cls != null) {

// *** I plan to have “Texas” and “Arizona” in a String array, so I will do this differently in a loop
// *** I won’t hard-code these values, because there could be 1 or more. For example: “Texas”, “Ohio”, and “Florida”

Object[] usrGrps = [ (IUserGroup)session.getObject(cls, “Texas”)]; // <– this will end up being an array of objects
usrGrps += [ (IUserGroup)session.getObject(cls, “Arizona”)]; // <– the += helped me here

cell.setValue(values); // <– this worked and added the two values

Agile Talent Answered on February 20, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.