I'd like to exclude an assignee based on whether that user is in a user picker field.

Hi guys,

I'm hoping this can be accomplished via script runner and/or the Behaviours plugin.

We have a workflow that has certain roles represented by user picker fields. Let's say we have an approver user picker and a reviewer user picker. Basically, if someone is specified in the reviewer picker, I want it to be impossible to assign the ticket to them. I personally don't care how.

I need something that can listen to either workflow or issue events. Thinking perhaps a listener... or maybe Behaviour?

Tips appreciated.


2 answers

1 vote

I would use a behaviour on the assignee to compare with the two other fields, and set it to invalid if it's the same, with a sensible message.

Think this will be easier and less confusing than trying to set the available assignees.

Hi Jamie,

I'm close – but I am missing something... which has caused my behaviour to stop working. This is what I have: 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
if (getActionName() != "Create Issue") {
    def assignee = getFieldById("assignee") as String
    FormField desRev = getFieldByName("Desired Reviewers")
    String reviewers = desRev.value as String
    def revCheck = reviewers.contains(assignee)
    def unCheck = (assignee == null || assignee.isEmpty() || assignee.trim().isEmpty())
    if (revCheck &! unCheck) {
        getFieldById("assignee").setError("Sorry, you cannot assign ${assignee} to this issue. " +
                "They are part of the \"Desired Reviewers\" group")
    else {

I think I am probably doing something really stupid – but for the life of me I can't figure out what. What I want to do is: 1. prevent  ability to assign any user from multiuser picker group "Desired Reviewers"  – if attempt is made, to throw an error. The desire is that it should work always (even during Ticket creation... though above example doesn't do that... perhaps you can suggest proper syntax). It should also be able to work via: the More --> Assign link in the task bar. 

Thanks Jamie - one silly question. How do you set the assignee as invalid? I'm assuming I shouldn't pass an empty string or Null?

getFieldById("assignee").setError("blah blah")

Don't forget to clearError() when the value is OK.

Thanks. The following seems to work:

def desRev = getFieldByName("Desired Reviewers")
def assigField = getFieldById("assignee")
String reviewers = desRev.getValue()
String assignee = assigField.getValue()
if (reviewers.contains(assignee))  {
    assigField.setError("Sorry -- you can't assign an issue to a reviewer.")
else {

However — I am able to bypass the behaviour im some situations. For example, if my user is in the "Desired Reviewers" group, I can still assign it to myself via the "Assign to myself" link. Or if I try to assign the the ticket by going to More --> Assign, I can still do it that way.  Am I missing something obvious?

Back up with a listener. Where you will listen for issue update events and if your condition is violated from the last update, you will "roll back". Hope you will find useful for a start the script below

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "assignee"}
if (change) {
    log.debug "Old assignee : ${change.oldstring}"
    log.debug "New assignee : ${change.newstring}"
    // if new assignee violates your conditions update the issue with the old assignee or null (unassigned)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

340 views 0 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you