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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script for removing assignee from user list - Post Function

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

0 votes
Answer accepted

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)

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

97 views 1 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you