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 votes
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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

240 views 0 11
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
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