We are trying to set a group picker (multiple groups) custom field (Stage Approver) using custom script post function.
Here is the script I am using. It is working for updating single group. Multiple groups is not working . Could anyone please guide me on this ?
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field
def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
issue.setCustomFieldValue(multiGroupCf, [TeamDatagroup])
How do i modify issue.setCustomFieldValue function such that i will be able to set more than one group?
Thanks
Swathi
Hi Swathi,
Have you tried adding your groups to a list and then setting the field using that list?
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Stage Approver") //multigroup picker custom field
def TeamDatagroup = groupManager.getGroup("TeamData Approvers") //jira group
def BOgroup = groupManager.getGroup("Business Owners") //jira group
def groupList = [TeamDatagroup, BOgroup]
issue.setCustomFieldValue(multiGroupCf, groupList)
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.
Hey Joshua Yamdogo @ Adaptavist, the above code works like a charm for post function but somehow it fails on custom listener. So I'm trying to update the group picker field when an issue is assigned to someone based on their group subscription.
Thanks in advance.
Madhu
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 How do i use this code to define the Group field based on the reporter's group?
Here is my version of modified code:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Assigned Group") //multigroup picker custom field
def Commercial = groupManager.getGroup("Commercial") //jira group
def EquityOps = groupManager.getGroup("EquityOps") //jira group
def Operations = groupManager.getGroup("Operations") //jira group
def groupList = [Commercial, EquityOps, Operations]
issue.setCustomFieldValue(multiGroupCf, groupList)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ankit Patel Could you explain more with a use-case example? Do you want to set the "Assigned Groups" field to all the groups that the reporter is in?
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Within the project a user belongs to only one group. So I want to set the "Assigned Group" to the group user belongs to within the project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ankit,
Something like this should work:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def assignedGroupCF = customFieldManager.getCustomFieldObjectByName("Assigned Group") //multigroup picker custom field
def assignedGroup = groupManager.getGroupsForUser(issue.getAssignee()) // get group for assignee
issue.setCustomFieldValue(assignedGroupCF , assignedGroup)
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.
Joshua Yamdogo @ Adaptavist - I have similar requirement, with one slight change in requirement.
We need to filter the group based on the project key. Let me know is it possible to achieve ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def assignedGroupCF = customFieldManager.getCustomFieldObjectByName("Assigned Group") //multigroup picker custom field
def assignedGroup = groupManager.getGroupsForUser(issue.getReporter()) // get group for assignee
issue.setCustomFieldValue(assignedGroupCF,assignedGroup)
So I put this rule and i started to notice it changed the assigned group field to more than 1 groups the user belonged to. What I was looking for is if there is a way to select the group the user is in within the project only?
Let me know if this is possible
Thanks
Ankit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.