Add all the associated groups of current logged in user to a custom field of Group Picker type

Ankita Sharma November 21, 2018

Hi Team,

 

I am using Jira Software Data Center v7.12.1 (SEN-L12515805) and JSD Data Center v3.15.1. I have added Script Runner add on.

 

I want to write a script which can add all the respective groups of the current logged in user to a new custom field of Group Picker type. How do we fetch associated groups of the current user?

 

Can you please help?

1 answer

0 votes
Mark Markov
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.
November 26, 2018

Hello @Ankita Sharma

Here is example to run in script console

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

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("multiGroupPicker customfield name")
def issue = issueManager.getIssueObject("TEST-1")
def groupForUser = groupManager.getGroupsForUser(currentUser)
issue.setCustomFieldValue(customField, groupForUser)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events