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

Accepted Answer
1 vote

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
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,551 views 5 6
Join discussion

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