Groovy Code Setting a multi group picker custom field based on value of cascading select list value

Deleted user October 24, 2017

We are trying to set a group picker (multiple groups) custom field (Stage Approver) using custom script post function.

Here is the script I am using. It is working for updating single group. Multiple groups is not working . Could anyone please guide me on this ?

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

issue.setCustomFieldValue(multiGroupCf, [TeamDatagroup])

 

How do i modify issue.setCustomFieldValue function such that i will be able to set more than one group?

 

Thanks 

Swathi

1 answer

1 accepted

4 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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 14, 2017

Hi Swathi,

Have you tried adding your groups to a list and then setting the field using that list?

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)
Deleted user November 14, 2017

Thank you Joshua Yamdogo @ Adaptavist !!

 

Regards

Swathi

Joshua Yamdogo @ Adaptavist
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 16, 2017

Hi @[deleted]

Glad to hear it worked. Please accept my answer as the accepted answer so others with the same problem can find the solution easier.

Thanks for using ScriptRunner!

Josh

Madhusudhan Matrubai December 11, 2017

Hey Joshua Yamdogo @ Adaptavist, the above code works like a charm for post function but somehow it fails on custom listener. So I'm trying to update the group picker field when an issue is assigned to someone based on their group subscription. 

Thanks in advance.

 

Madhu

Ankit Patel April 6, 2018

Joshua Yamdogo @ Adaptavist How do i use this code to define the Group field based on the reporter's group? 

 

Here is my version of modified code: 

 

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

def Commercial = groupManager.getGroup("Commercial") //jira group
def EquityOps = groupManager.getGroup("EquityOps") //jira group
def Operations = groupManager.getGroup("Operations") //jira group
def groupList = [Commercial, EquityOps, Operations]
issue.setCustomFieldValue(multiGroupCf, groupList)
Joshua Yamdogo @ Adaptavist
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.
April 9, 2018

@Ankit Patel Could you explain more with a use-case example? Do you want to set the "Assigned Groups" field to all the groups that the reporter is in?

Josh

Ankit Patel April 9, 2018

Joshua Yamdogo @ Adaptavist

Within the project a user belongs to only one group. So I want to set the "Assigned Group" to the group user belongs to within the project.

Joshua Yamdogo @ Adaptavist
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.
April 12, 2018

Hi Ankit,

Something like this should work:

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def assignedGroupCF = customFieldManager.getCustomFieldObjectByName("Assigned Group") //multigroup picker custom field

def assignedGroup = groupManager.getGroupsForUser(issue.getAssignee()) // get group for assignee
issue.setCustomFieldValue(assignedGroupCF , assignedGroup)
Ankit Patel April 23, 2018

Thanks Joshua 

 

That did work out for me!

Manikandan K April 25, 2018

Joshua Yamdogo @ Adaptavist - I have similar requirement, with one slight change in requirement.

We need to filter the group based on the project key. Let me know is it possible to achieve ?

 

https://community.atlassian.com/t5/Jira-questions/Restrict-the-group-picker-based-on-project-key/qaq-p/780903#M252492 

Ankit Patel May 17, 2018

Joshua Yamdogo @ Adaptavist

 

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def assignedGroupCF = customFieldManager.getCustomFieldObjectByName("Assigned Group") //multigroup picker custom field

def assignedGroup = groupManager.getGroupsForUser(issue.getReporter()) // get group for assignee
issue.setCustomFieldValue(assignedGroupCF,assignedGroup)

 

So I put this rule and i started to notice it changed the assigned group field to more than 1 groups the user belonged to. What I was looking for is if there is a way to select the group the user is in within the project only? 

 

Let me know if this is possible 

 

Thanks
Ankit

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events