Can I restrict assignee selection to members of a group picker custom field?

Adam Gaudry November 20, 2017

Hi 

I am trying to create a notification scheme that will send a notification to one of five "tech approver" groups created in JIRA, when the ticket reaches a certain part of the workflow (ie "awaiting tech approval").

I have created a post-function on the transition to the "awaiting tech approval" stage. The post-function fires an event, which in turn notifies the group specified in a custom field group picker in the ticket.

The problem is that when entering the group in the field, you can see ALL of JIRA's groups. Which is a lot more than five.

Is there a way of limiting the number of groups?

Alternatively, I would like to create a dropdown custom field picker, where the user selects an "area" that is mapped to the appropriate group. (ie picking "Enterprise" in the field would then result in a post-function mapping Enterprise to "tech-notify-enterprise"). Is there any way of doing this?

Thanks for your time.

2 answers

1 accepted

3 votes
Answer accepted
miikhy
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 29, 2017

==== UPDATE FROM Oct 29th, 2018 ====

Please scroll in comments for an updated answer and an alternative method.

==== ORIGINAL CONTENT ====

Hi Adam,

My suggestion would be to edit your permission scheme and grant the "Assignable User" permission to a group custom field value as described below:cfAssignee.png

That would only allow users from the group in the custom field to be assignee. Please note that this will apply to the whole project and you'll need to carefully prefill this custom field with the relevant group at all time! The custom field value could be easily changed from a status to another using post functions.

Would that work?

Thanks

Adam Gaudry December 20, 2017

Thanks very much Mickey. I don't think that would work for us because we still require the ticket to be assigned to someone else, we're just looking to notify one of a few groups. However, that is a really interesting feature and one I might use in future!

Best wishes and Merry Christmas

Adam

miikhy
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.
January 4, 2018

Hi Adam,

Thanks for your feedback and sorry for my delayed response!

You have a happy new year and best luck with Jira :)

Adam Gaudry January 5, 2018

Thanks you too Micky.

In the end this was the solution I devised with the help of a colleague and the community. 

  1. I have the group picker, which is a single group custom field, which cannot be edited (by omitting it from the create/edit screen). I call this field "Technical Approvers Groups"
  2. I have a second custom field, which is a single choice, drop-down select list. This is a mandatory field on the create/edit screen. I call this "Change Area".
  3. I have a custom scripted field that is made using Scriptrunner. I use this to map the value from the select list in step 2, to the group picker in step 1. This custom field is hidden from view and works in the background. It is only applied to the project for which I'm using it. It uses the following script.
    import com.atlassian.jira.component.ComponentAccessor;
    import com.atlassian.jira.issue.CustomFieldManager;
    import com.atlassian.jira.issue.Issue;
    import com.atlassian.jira.issue.fields.CustomField;
    import com.atlassian.jira.issue.MutableIssue;
    import com.atlassian.jira.issue.ModifiedValue;
    import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

    MutableIssue issueToUpdate = (MutableIssue) issue;

    // create the map of Change Area names to approval groups
    def approvalGroupMap = [
    "TA Group 1" : "tech-approval-group1",
    "TA Group 2" : "tech-approval-group2",
    "TA Group 3" : "tech-approval-group3",
    "TA Group 4" : "tech-approval-group4",
    "TA Group 5" : "tech-approval-group5"
    ];

    // get the value of the "Change Area" field
    def changeAreaFieldObject = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_XXXXX");
    def changeArea = issue.getCustomFieldValue(changeAreaFieldObject).toString();

    //configure and define the value taken from the "Change Area" field as a group, rather than a simple string (this is necessary)
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = groupManager.getGroup(approvalGroupMap[changeArea])

    //taking the group value defined immediately above, use it to set Techical Approvers Group field
    def tgtField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == "Technical Approvers Groups"}
    def changeHolder = new DefaultIssueChangeHolder();
    def mv = new ModifiedValue(issue.getCustomFieldValue(tgtField), [group]);
    tgtField.updateValue(null, issue, mv,changeHolder);

    //test with a return group to make sure it is working.
    return group

    What all this allows me to do is have a user-friendly and limited choice custom field, with option names I can control and which are mapped on the back end to specific JIRA groups.

  4. I have a custom notification, which alerts the group mapped in the custom field Technical Approvers Groups. 
  5. Finally I set up a post-action on a transition (called Submit for Review) that fires the notification out to the appropriate approver group.

Hope this helps anyone thinking about doing something similar!

Best wishes

Adam

Like # people like this
miikhy
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.
January 5, 2018

Great, interesting! Thanks for sharing!

Alvin
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 11, 2018
0 votes
Alvin
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 11, 2018

Hi @Adam Gaudry, how did you managed to populate the Assignee field based on users on its group?

Adam Gaudry October 29, 2018

Hi Alvin

Sorry for the delayed response. I didn't populate the assignee field; what my solution does is populate a group field based on a single choice, drop-down select list.

It's a bit like this:

Custom field A = single choice, drop-down select list. There are 5 different options in this field, so you can select either option 1, 2, 3, 4, or 5.

Custom field B = single group field. 

Custom field C = this is a scripted field configured using Scriptrunner, that essentially takes the value of the choice in Custom field A and turns it to string, so it can be mapped to groups for Custom field B. 

Then in practice, when sometime makes a choice in Custom Field A, the scriptrunner field maps it to a group (according to its script, see above for more info), and the group gets selected in Custom field B.

Once that has run, I have set up the notification scheme so that the group defined in Custom field B is notified when a ticket is submitted for review.

Hope that makes sense.

Alvin
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 29, 2018

Hi @Adam Gaudry , do you have sample code to work with? Thank you

Adam Gaudry November 1, 2018

Hi Alvin, the code I'm using is pasted above.

Like Alvin likes this
Tim Eddelbüttel
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 23, 2018

Thanks @Adam Gaudry

Suggest an answer

Log in or Sign up to answer