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

This widget could not be displayed.

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 {
        getFieldById("assignee").clearError()
    }
}

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. 

This widget could not be displayed.

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 {
    assigField.clearError()
    
}

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

160 views 2 0
Join discussion

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