Can I update a multi user picker custom field with members of particular group upon issue creation?

Deleted user November 6, 2017

Hello All,

 

Did anyone tried updating a multi user picker field with members of a particular group using groovy post function (custom script)?

My use case : Upon issue creation i want my custom field CM Approvers (Multi user picker) to update automatically with setting the value to all members of a group "CM". Is this possible? If so, what would be the sample groovy code?

 

Also, if this is not possible using script runner, is there any other add-on through which we can implement this functionality ?

 

Many thanks !

Swathi

4 answers

1 accepted

3 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,

You can definitely update a multi-user picker field with users from a group. In fact, I recently helped someone accomplish this in a different Community question. See here: https://community.atlassian.com/t5/Jira-Service-Desk-questions/Using-Scriptrunner-to-define-approvers-based-on-multiple-groups/qaq-p/664935#M8176

Your script might look something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def group = groupManager.getGroup("CM") // get the CM group
def usersInGroup = groupManager.getUsersInGroup(group) // get the users in that group
def fieldToSet = customFieldManager.getCustomFieldObjectByName("CM Approvers") // get the CM Approvers custom field
fieldToSet.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fieldToSet), usersInGroup), new DefaultIssueChangeHolder()) // update CM Approvers with users
Deleted user November 14, 2017

Hey Joshua Yamdogo @ Adaptavist ,

 

Thanks so much. It worked like charm!

 

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 8, 2017

Joshua Yamdogo @ Adaptavist

On the same note, can you please advise on how to update a field of the type "multi group picker". 

Steve Letch September 2, 2019

Hi Joshua Yamdogo @ Adaptavist 

 

I know this is a little old but I'm having trouble with your script

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def group = groupManager.getGroup("Senior Mgt Change Approver Group") // get the CM group
def usersInGroup = groupManager.getUsersInGroup(group) // get the users in that group
def fieldToSet = CustomFieldManager.getCustomFieldObjectsByName("Approvers.") // get the CM Approvers custom field
fieldToSet.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fieldToSet), usersInGroup), new DefaultIssueChangeHolder()) // update CM Approvers with users

 

Screenshots show errors

Screenshot 2019-09-02 at 10.50.22.pngScreenshot 2019-09-02 at 10.50.16.png

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.
September 6, 2019

@Steve Letch : "CustomFieldManager" should be "customFieldManager" with a lowercase 'c' in that script 

Kiran Kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 25, 2020

Joshua Yamdogo @ Adaptavist Thank you for your help!

0 votes
Michael Salvio March 23, 2020

Hello Joshua Yamdogo @ Adaptavist ,

I hope all is well with you and your family during this time:) 

I am working on the first code you gave in this comment which works great!

However we have a requirement to do the opposite add users from a multi-user custom field to a group. Can you assist me with modifying the code?

Thank you! 

Michael Salvio March 23, 2020

Just clarify we would like to update the user group from the multi-user picker not replace the group with the contents of the multi-user picker.

Thank you!

0 votes
Rexel USA September 9, 2019

Hey all!  So this solution is ideal for something I'm implementing, however I need to apply this based on a field value.  In otherwords, if custom field equals x, set multi-user picker to the members of this group.  Any suggestions on how to tweak this code to accommodate?

Steve Letch September 10, 2019

Do you have Jira Misc Workflow Extension plugin?

 

I'm using 'Set field value' JMWE with a Groovy expression and a condition

 

The value of field Approvers of the current issue will be set to the value of the following Groovy Expression:

ComponentAccessor.groupManager.getUsersInGroup("Engineering Automations")

(replacing existing values).

Run this post-function only if the following condition is true:

issue.get("customfield_13336")?.any{it.name == "Engineering"}
sekhar reddy
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 27, 2023

Hi @Steve Letch 

I am using Jira Misc workflow extension plugin, my requirement is

I am using Multi group picker field for the approval, is it possible to get the list of user who are in those groups and updated in the Approvers multi user field.?

Thank you.

0 votes
Alibek Malikov August 5, 2019

Hi everyone, I can’t do one functional in jira system using script runner script post function
I need to make sure that when choosing a component when creating a task, groups with users who are responsible for a particular component are added,
For example, there is a component; "Coca Cola" is responsible for this component; "CocaGP"
And if, when creating a request, the user selects the "Coca Cola" component, then in this case, the CocaGP group will be added to the field called "Manager Group".
If someone can help me please, please, I will be very grateful)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events