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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,266
Community Members
 
Community Events
184
Community Groups

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

Deleted user Nov 06, 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.
Nov 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 Nov 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.
Nov 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

@Joshua Yamdogo _ Adaptavist

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

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.
Sep 06, 2019

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

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! 

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!

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?

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 Idamakanti
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.
Apr 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.

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