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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On the same note, can you please advise on how to update a field of the type "multi group picker".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Never mind, found the solution here: https://community.atlassian.com/t5/Jira-questions/Groovy-Code-Setting-a-multi-group-picker-custom-field-based-on/qaq-p/660126
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Steve Letch : "CustomFieldManager" should be "customFieldManager" with a lowercase 'c' in that script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Joshua Yamdogo @ Adaptavist Thank you for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.