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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 Opsgenie

Opsgenie and Amazon team up to launch new DevOps Guru integration - now available!

We’re proud to announce that our integration with Amazon DevOps Guru is now live. The Amazon and Opsgenie product teams have worked together to build a deep integration between Opsgenie and the new...

242 views 0 7
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