custom user picker based on select list value in postfunction using scriptrunner

Hi,

I want to change value in customfield user picker (single) to specific user based on customfield select List (single) chosen value. In all cases I know which values in select list equal which users in user picker.

It goes on like this:
- if customfield "Category of Issue" = "First Category" or "Second Category" -> change "Responsible Agent" to "John"
- if customfield "Category of Issue" = "Third Category" -> change "Responsible Agent" to "Bob"

2 answers

0 vote
Tarun Sapra Community Champion Aug 14, 2017

This has been discussed many times on this forum.

You first need to fetch the values of user pircker field and then update the drop-down field's value.

Here's an sample - https://community.atlassian.com/t5/JIRA-questions/Updating-a-custom-field-using-groovy-script-runner/qaq-p/256708

Thank you @Tarun Sapra, however none of examples provided includes following logic:


if in field is this OR this selected = change this user picker field to this user

Below is custom script, however it gives an error.
I used similar script (without if statement) for Fast-track transition, where it worked.
I placed custom script after "Fire a" event in post function.

Can you kindly advise why custom script is not working?

JIRA v7.3

Custom Script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Responsible Agent Team");
def userManager = ComponentAccessor.getUserManager()
def user_tier2engineer = userManager.getUserByName("sst2engineer")
def user_tier2specialist = userManager.getUserByName("sst2specialist")

if (cfValues['IT / Casino Issue Category']?.value == 'Internal game issue'){
issue.setCustomFieldValue(CF, user_tier2engineer);
}
else { issue.setCustomFieldValue(CF, user_tier2specialist);
}


ERROR:

2017-08-21 11:07:04,224 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-08-21 11:07:04,236 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SD-903, actionId: 241, file: <inline script>
groovy.lang.MissingPropertyException: No such property: cfValues for class: Script275
at Script275.run(Script275.groovy:20)

 


Fast-track transition script that works:

Condition:
cfValues['IT / Casino Issue Category']?.value == 'Internal game issue'

Additional issue actions:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor


IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Responsible Agent Team");
def userManager = ComponentAccessor.getUserManager()
def user_tier2engineer = userManager.getUserByName("sst2engineer")
issue.setCustomFieldValue(CF, user_tier2engineer);

Thanks in advance! 

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

76 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