Hello!
I would like to iterate over a custom field of type multi group picker in groovy to create separate tickets for each group in my custom field. The split itself is working fine no worries (in another scenario with ApplicationUsers being a collection). The thing that is not working is to have the iteration over the groups in that multi group picker field. I think I have an issue with the collection supplying not the group name but some internals. Here is the relevant code snippet there is some other code ... which works fine and has no influence to the issue:
log.setLevel(Level.DEBUG)
log.debug "Split issue STARTED"
CustomField supportersCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(13704) // customField All Supporters (Multi-Group-CustomField)
Collection<String> groups= (Collection) issue.getCustomFieldValue(supportersCf)
log.debug "Choosen source customField: " + supportersCf
groups.each { it ->
log.debug "GroupSplit loop STARTED"
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setProjectId(issue.projectId)
newIssue.setDescription(issue.description)
newIssue.issueTypeId = "11601"
log.debug "Assignee: " + newIssue.getAssignee()
...
newIssue.setCustomFieldValue(customFieldManager.getCustomFieldObject(13704), it) // customField All Supporters (Multi-Group-CustomField)
newIssue.setSummary(issue.getCustomFieldValue(surname) + ", " + issue.getCustomFieldValue(firstname))
Map<String, Object> newIssueParams = ["issue": newIssue] as Map<String, Object>
issueManager.createIssueObject(currentUser, newIssueParams)
IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager()
log.debug("Issue Link Types : " + IssueLinkType)
linkManager.createIssueLink(issue.getId(), newIssue.getId(), 10400, 1, currentUser);
log.debug "GroupSplit loop END"
}//each end
log.debug "Split issue END"
Any help is highly appreciated!!
Thank you!
Hi Nico,
Not sure what exactly is going wrong, as I don't see what does the log say. But simply looking at your code I think your problem might be here:
newIssue.setCustomFieldValue(customFieldManager.getCustomFieldObject(13704), it)
You are setting a value fora multi-group picker type field. The expected value for this field type is a collection of 'group' objects and you are trying to pass a single group. What you need to do, is to create a new collection, add your group to it and then pass this collection (yes, it will only have a single element in it) to your field, like so:
import com.atlassian.crowd.embedded.api.Group
List<Group> groupList = new ArrayList<>()
groupList.add(it)
newIssue.setCustomFieldValue(customFieldManager.getCustomFieldObject(13704), groupList)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.