Set assignee per field "Team"

Eran Nir December 5, 2017

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 votes
Udo Brand
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.
December 5, 2017

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).

Eran Nir December 5, 2017

Hi, thanks.

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

0 votes
Alexey Matveev
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.
December 5, 2017

Hello,

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

Eran Nir December 5, 2017

Hi, thanks 

 

this wouldn't help?

https://community.atlassian.com/t5/Jira-questions/Set-assignee-based-on-custom-field-value/qaq-p/674988

 

If so, where do I add this code?

Eran Nir December 5, 2017

if so, where do I add this code?

Alexey Matveev
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.
December 5, 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

Eran Nir December 11, 2017

@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
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.
December 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))
Eran Nir December 11, 2017

@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
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.
December 11, 2017

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

Eran Nir December 12, 2017

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
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.
December 12, 2017

Where do you put the script?

Eran Nir December 12, 2017

@Alexey Matveev In the work flow post function:

 

pf.png

Eran Nir December 12, 2017

@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
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.
December 12, 2017

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

Eran Nir December 12, 2017

@Alexey Matveev

 

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

 

11.png

Alexey Matveev
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.
December 12, 2017

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

issue.store()

Eran Nir December 12, 2017

@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
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.
December 12, 2017

Yes, that is what I mean

Eran Nir December 12, 2017

@Alexey Matveev

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

Thanks so much for your support

Suggest an answer

Log in or Sign up to answer