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

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

1 answer

1 accepted

This widget could not be displayed.

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

Hey @Joshua Yamdogo [Adaptavist] ,

 

Thanks so much. It worked like charm!

 

Regards,

Swathi

Hi @Swathi Komirelli [Appfire]

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". 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 9 hours ago in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

52 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you