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

Bryan_Karsh October 13, 2016

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
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2016

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.

Bryan_Karsh October 21, 2016

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. 

0 votes
Bryan_Karsh October 17, 2016

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?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2016
getFieldById("assignee").setError("blah blah")

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

Bryan_Karsh October 17, 2016

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?

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2016

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)
}
Like David Puchosic likes this

Suggest an answer

Log in or Sign up to answer