Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script for removing assignee from user list - Post Function

Cary Watkins September 4, 2018

I am using a post function to set a list of users for an approval step. As they are internal approvers, I do not want the Assignee to approve the ticket. 

Below is what I have thus far - apologies for the mess, I'm sure there is a better way. Very basic: Approvers field, get the name of the group of approvers from cf10209, finds the people in that group, and applies it to the Approvers field. This currently works, but it is a full list of everyone in that group - I need help figuring out a way to only gather those users not equal to the issue.assignee... 

import com.atlassian.jira.issue.ModifiedValue 
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.IssueManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def approversField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Approvers"}
def assignedGroupValue = customFieldManager.getCustomFieldObject("customfield_10209").getValue(issue)
def changeHolder = new DefaultIssueChangeHolder()
def assignee =issue.getAssignee()

def usersInGroup = groupManager.getUsersInGroup(assignedGroupValue)

approversField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(approversField), usersInGroup),changeHolder)

 Any help would be appreciated... Everything I find online tells about making changes to the actual group. 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Mark Markov
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.
September 5, 2018

Hello @Cary Watkins

You can filter user like this

import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def approversField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Approvers"}
def assignedGroupValue = customFieldManager.getCustomFieldObject("customfield_10209").getValue(issue)
def changeHolder = new DefaultIssueChangeHolder()
def assignee =issue.getAssignee()

def usersInGroup = groupManager.getUsersInGroup(assignedGroupValue).findAll {!it.equals(assignee)}

approversField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(approversField), usersInGroup),changeHolder)
Cary Watkins September 5, 2018

Great suggesting Mark. Works exactly how I needed it to. 

TAGS
AUG Leaders

Atlassian Community Events