Jira Groovy Scripting from custom field to Custom User Picker

Hi,

I would like to find a way using AdaptavistScript Runner how to set a Custom User Picker Field after selecting an Option from a Select List (Single Choice) when creating an issue.

Example: If I choose Product A, I would like the Product Owner to be username1

Can someone please give some tips on how I can set this up?

Cheers

1 answer

0 vote
Vasiliy Zverev Community Champion Oct 19, 2016

Here is code example for your case. I did not tested it, but it should work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option

String userName;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

switch(((Option) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Select List"))).getValue()){
    case "Option 1": userName = "user 1";break;
    case "Option 2": userName = "user 2";break;
    case "Option 3": userName = "user 3";break;
}

issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Custom User Picker Field")
        , ComponentAccessor.getUserManager().getUserByName(userName) )

Thanks a lot for your promt reply,

For some reason, I get this error message:

image2016-10-19 16:17:35.png

 What do I need to declare? 

What is the context where you are running this, eg a post-function? A screenshot of the whole page would help here.

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 Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

1,125 views 3 12
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