Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Update multi picker group via custom listener

Hi There,

The following groovy code works fine on a post function but doesn't on custom listener of "Assign" or "Update" event.

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field

def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
def groupList = [TeamDatagroup, BOgroup]
issue.setCustomFieldValue(multiGroupCf, groupList)

 

Can someone please advise on why that could be and how to fix this.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Alexey Matveev
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.
Dec 12, 2017

It would be something like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field

def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
def groupList = [TeamDatagroup, BOgroup]
def curUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
event.issue.setCustomFieldValue(multiGroupCf, groupList)

ComponentAccessor.getIssueManager().updateIssue(curUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Awesome, works like a charm @Alexey Matveev . Appreciate your help.

 

One more quick followup question if you can, when I update this multipicker group field it's over writing all the existing content. Is it possible to append the group to the existing values in this field?

Alexey Matveev
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.
Dec 13, 2017

It would be something like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field

def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
def groupList = [TeamDatagroup, BOgroup]
def curUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def groupListCur = event.issue.getCustomFieldValue(multiGroupCf)
groupList = groupList.addAll(groupListCur)
event.issue.setCustomFieldValue(multiGroupCf, groupList)

ComponentAccessor.getIssueManager().updateIssue(curUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

I did not check the code, but the idea is to retrieve the current value of the custom field which would be also an array and then add your array to it. and then save the combined array to the custom field

Thanks @Alexey Matveev that's helpful. I tried something similar to what you advised(except to my rookie knowledge on groovy, so please excuse that)  it's complaining about the following

2017-12-13 09:40:58,701 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2017-12-13 09:40:58,701 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Collection
 at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.updateValue(AbstractMultiCFType.java:39)
 at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:425)
 at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:395)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655)
 at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:214)
 at com.atlassian.jira.issue.IssueManager$updateIssue$3.call(Unknown Source)
 at Script217.run(Script217.groovy:18)
Alexey Matveev
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.
Dec 13, 2017

Try like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field

def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
def groupList = [TeamDatagroup, BOgroup]
def curUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def groupListCur = event.issue.getCustomFieldValue(multiGroupCf)
groupList.addAll(groupListCur)
event.issue.setCustomFieldValue(multiGroupCf, groupList)

ComponentAccessor.getIssueManager().updateIssue(curUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Thanks Alex for your continued support. That worked like a charm, you are a star. Appreciate all your help.

 

Hi All,

Could you please advise how can I remove one group from multiGroupCf, for example if I want to remove only 'Business Owners' group from the field, and want to leave others still in the field?

My code does not work:

accessGroups.remove(group);

multiGroupCf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(multiGroupCf), [accessGroups]),changeHolder)

 

I get following error:

2021-08-03 23:07:16,769 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.atlassian.crowd.embedded.api.Group at com.atlassian.jira.issue.customfields.impl.MultiGroupCFType.convertTypeToDbValue(MultiGroupCFType.java:86) at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.convertTypesToDbObjects(AbstractMultiCFType.java:196) at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.updateValue(AbstractMultiCFType.java:142) at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.updateValue(AbstractMultiCFType.java:39) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:426) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.fields.OrderableField$updateValue$3.call(Unknown Source) at Script386.run(Script386.groovy:50)

TAGS
AUG Leaders

Atlassian Community Events