Set assignee per field "Team"

Hi,

I have a requirement, that when a jira ticket opens the default assignee will be related to the selected team.

 

So, if i set the field "team" when I create a new jira, (with team "X"), when it opens the jira assignee will be "John"

and for team "Y" the assignee will be "David"

I pretty new with Jira so if you can direct me specifically it will be great.

Thanks  

2 answers

0 vote
Alexey Matveev Community Champion Dec 05, 2017

Hello,

It is not possible out of the box. You would need develop a custom plugin.

if so, where do I add this code?

Alexey Matveev Community Champion Dec 05, 2017

It would help. You need to install Adaptivist ScriptRunner first. It is not a free add on. Then you would add a post function to the transition where you set your team field

@Alexey Matveev

Hi, for some reason we cant make it work....

here is our post function:

---------------------------------------------------------------
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssue
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()def team = customFieldManager.getCustomFieldObject("customfield_12801")def fieldValue = team.getValue(issue);


switch(fieldValue){    case "Jira Engage-Default": userName = "shaked";break;    case "Jira Test": userName = "kobi";break;    case "Jira Default": userName = "enir";break;    }
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
---------------------------------------------------------------

 

 

The custom field this script tries to access ( customfield_12801 ) , its a Group picker , so we need to get the value from this field, compare it to the text strings , and set the assigned accordingly.

can you please assist?

 

Thanks

Alexey Matveev Community Champion Dec 11, 2017

The problem is that team.getValue(issue) returns List<Group> not a String. That is why you should write like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.Group
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def team = customFieldManager.getCustomFieldObjectByName("customFieldName")
def fieldValue = team.getValue(issue);

switch(fieldValue?.get(0)?.getName()){ case "Jira Engage-Default": userName = "shaked";break; case "Jira Test": userName = "kobi";break; case "Jira Default": userName = "enir";break; }
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))

@Alexey Matveev

Thanks very much!

 

This is the code I placed:

 

import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.crowd.embedded.api.GroupString userName;def customFieldManager = ComponentAccessor.getCustomFieldManager()def team = customFieldManager.getCustomFieldObject("customfield_12801")def fieldValue = team.getValue(issue);
switch(fieldValue?.get(0)?.getName()){ case "Jira Engage-Default": userName = "shaked";break; case "Jira Test": userName = "kobi";break; case "Jira Default": userName = "enir";break; }issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))

 

and this is the error I get:

 

error.png

 

What do we do wrong?

thanks

Alexey Matveev Community Champion Dec 11, 2017

It is just a static compilation error. Do not pay attention to it, it will work just fine

thanks @Alexey Matveev very much.

 

We have a progress...

But we see that after using the code above, the Jira ticket is opened but the assignee is not the requested/set in code.

we see a weired behavior:

1)the assignee in the Jira ticket itself is not the requested assignee as in the script but it set assignne "unassigned" or the default assignee of the Jira project.

2)the assignee in the created issue mail notification from Jira (from the same jira ticket)  is the requested from the script.

 

see screen shots:

1)The Jira ticket itself- has assignee "unassigned"

ticket.png

 

2)The assignee in the email notification from Jira )for the same ticket), is the right assignee as in the script.

 

iN MAIL.png

Alexey Matveev Community Champion Dec 12, 2017

Where do you put the script?

@Alexey Matveev In the work flow post function:

 

pf.png

@Alexey Matveev

Here is the script:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.Group
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def team = customFieldManager.getCustomFieldObject("customfield_12801")

def fieldValue = team.getValue(issue);

switch(fieldValue?.get(0)?.getName())
{
case "Jira Engage-Default": userName = "shaked"; break;
case "Jira Engage-Widgets-Cats": userName = "nalook"; break;
case "Jira Organic campaigns": userName = "tmagen" ;break;
case "Jira Engage Reports": userName = "vioffe" ;break;
case "Jira organic recs": userName = "itamir" ;break;
case "Jira Amplify- Default": userName = "zbarak" ;break;
case "Jira Amplify-API-Buyers": userName = "nfriedrich" ;break;
case "Jira Amplify-Pics-Pixels-Impressions-Clicks-Segments": userName = "amatar" ;break;
case "Jira Amplify-Dashboard-Selfserve": userName = "ngeva" ;break;
case "Jira paid recs": userName = "drosenstein" ;break;

}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName));

Alexey Matveev Community Champion Dec 12, 2017

Put this script before  Number 2 Re-index an issue to keep indexes in sync with the database

@Alexey Matveev

 

I moved it, and still the same behavior... (email OK, ticket wrong assignee), any other thoughts?

 

11.png

Ok. It must be number 2. It is ok. add the last line to the script

issue.store()

@Alexey Matveev

you mean like this:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.Group
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def team = customFieldManager.getCustomFieldObject("customfield_12801")

def fieldValue = team.getValue(issue);

switch(fieldValue?.get(0)?.getName())
{
case "Jira Engage-Default": userName = "shaked"; break;
case "Jira Engage-Widgets-Cats": userName = "nalook"; break;
case "Jira Organic campaigns": userName = "tmagen" ;break;
case "Jira Engage Reports": userName = "vioffe" ;break;
case "Jira organic recs": userName = "itamir" ;break;
case "Jira Amplify- Default": userName = "zbarak" ;break;
case "Jira Amplify-API-Buyers": userName = "nfriedrich" ;break;
case "Jira Amplify-Pics-Pixels-Impressions-Clicks-Segments": userName = "amatar" ;break;
case "Jira Amplify-Dashboard-Selfserve": userName = "ngeva" ;break;
case "Jira paid recs": userName = "drosenstein" ;break;

}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName));

issue.store()

Alexey Matveev Community Champion Dec 12, 2017

Yes, that is what I mean

@Alexey Matveev

hi, it works!!!!!! you are great

Thanks so much for your support

Well, what you want sounds like the behaviour of the components Field. Instead of "Team" use Component "X" (with default assigee John) or use Component "Y"( with default assignee David).

Hi, thanks.

Where do I add this? do you gave an example?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

75 views 0 5
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