Set assignee based on custom field value

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

1 answer

1 accepted

0 votes
Alexey Matveev Community Champion Nov 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))

Hi Alexey

 

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

any idea ?

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

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 Community Champion Feb 02, 2018

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

Alexey Matveev Community Champion Feb 02, 2018

What is your jira version?

Alexey Matveev Community Champion Feb 02, 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)))

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,156 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot