How to loop though an ArrayList
The example below shows how we can ‘find’ users, then join them together CSV, to be then put in a multi-user picker field - in JEMH, all values are plain text.
Javadoc
When working with Jira, there is a lot of supporting javadoc available through the “Velocity Context” on the script edit page:
Eg google for “UserSearchService Jira” and you’ll get:
It's not obvious but findUsersByFullName(String fullName) returns an Iterable<ApplicationUser> , the concrete type that implements that is typically a List of some kind (https://docs.oracle.com/javase/8/docs/api/java/util/List.html ), you can see that javadoc for how to know there is a .size() method for use in the javascript loop construct shown
Example script
var n = userSearchService.findUsersByFullName("admin");
var recordCount = n.size();
print('record count: '+recordCount);
var csv='';
for (var i = 0; i < recordCount; i++) {
var aUser = n.get(i);
csv+=aUser.getUsername();
if (i+1 < recordCount) {
csv+=',';
}
}
resultMap.put("MultiUserPicker", csv);