Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy iterate over Multi Group Picker custom field

Nico Hoffmann December 11, 2018

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!

1 answer

0 votes
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2018

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)

Suggest an answer

Log in or Sign up to answer