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
Mark Markov Community Leader Sep 05, 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)

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Opsgenie

DevOps Just Got a Whole Lot Easier with Opsgenie and AWS CloudFormation Registry and CLI

...esponders": [{ "type": "team", "name": { "Fn::GetAtt": [ "NemoSearchParty", "Name" ] } }], "Enabled": true }, "DependsOn": [ "TeamA" ] }, "C...

885 views 0 10
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