Set assignee based on custom field value

Shlomi Cohen November 19, 2017

Hi

 

I want to add a postfunction script that sets the assignee based on a custom fields value.

So for example when field 'Product' (Select List Single Choice) a has value 'Cloud' then it should be assigned to person 'gwll' user name. If it's value 'Server' then it should be person 'Johnl' user name. We do have scriptrunner, can anybody tell me how the script should look to enable this?

I tried the following script but it set the assignee value on issue as unassignee 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

String userName;

switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Product").toString()){
case "Cloud": userName = "gwll";break;
case "Server": userName = "Johnl";break;

}

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

 

Jira - 7.2.7

ScriptRunner - 5.2.1

 

thanks for your help

2 answers

1 accepted

1 vote
Answer accepted
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.
November 19, 2017
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
String userName;
def csProduct = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Product")
switch(issue.getCustomFieldValue(csProduct)){
case "Cloud": userName = "gwll";break;
case "Server": userName = "Johnl";break;

}
log.error(userName)
log.error(issue.getCustomFieldValue(csProduct));
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
Shlomi Cohen November 19, 2017

Hi Alexey

 

thanks for quick reply, I am getting same results - the Assignee value set to Unassigned value

any idea ?

Shlomi Cohen November 19, 2017

Sorry it's works. there is two Product custom fields 

Chiara Squilloni February 2, 2018

Hi @Alexey Matveev

I'm using a similar post function:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue;
String userName;
def areaRiferimento = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Area di riferimento")
switch(issue.getCustomFieldValue(areaRiferimento)){
    case "Qualità": userName = "mfaedda";break;
    case "Sicurezza": userName = "acubeddu";break;

}

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

 

But the inline script return me an error: "Cannot find matching method"

What I am missing?

Thank you so much.

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.
February 2, 2018

Do you mean you hava a static compilation error? Could you provode a screenshot?

Like Amine Tanboura likes this
Chiara Squilloni February 2, 2018

Immagine.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.
February 2, 2018

What is your jira version?

Chiara Squilloni February 2, 2018

6.4

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.
February 2, 2018

Try like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.user.ApplicationUsers

MutableIssue issue = issue;
String userName;
def areaRiferimento = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Area di riferimento")
switch(issue.getCustomFieldValue(areaRiferimento)){
    case "Qualità": userName = "mfaedda";break;
    case "Sicurezza": userName = "acubeddu";break;

}

issue.setAssignee(ApplicationUsers.from(ComponentAccessor.getUserManager().getUserByName(userName)))
Like Amine Tanboura likes this
Chiara Squilloni February 23, 2018

Sorry, also this does not work. I will work again on it after the jira update.

Rachid Amajoud May 18, 2018

hi,

i've also an issue with implementing this, i am using the following script:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.MutableIssue

String userName;

switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Division").toString()){

    case "AB": userName = "Tom";break;

    case "CD": userName = "Tom";break;

    case "EF": userName = "Steven";break;   

    case "GH": userName = "Steven";break;

}

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

I made a custom field (Radiobutton) and added to some screens, how should this work?

We have scriptrunner but i cant't choose for radiobutton? Is there any advice?

 

thx!

0 votes
Amine Tanboura October 18, 2022

Hello @Alexey Matveev _Appfire

I tested your code and it's working

Thank you

Regards,

Amine Tanboura,

Suggest an answer

Log in or Sign up to answer