Creating a Scripted Field (User Picker) Based on Another Field

Neiman Marcus Atlassian Support June 27, 2018

We have two custom fields - CFA (text) and CFB (ScriptRunner - Scripted Field). CFA contains a code that represents a user. We need the script in Scripted Field CFB to match that code and return the corresponding username. When I run this script using Text Field template, I get <username>(<username>). with the correct username. But when I change the template to User Picker, I get "Anonymous." Please help me figure out how to get the User Picker to work.

Jira Software Server - 7.5.3

Adaptavist ScriptRunner for JIRA - 5.3.26

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

def userManager = ComponentAccessor.getUserManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfa= customFieldManager.getCustomFieldObject("customfield_18430")
def cfavalue= issue.getCustomFieldValue(cfa)
def id = null
switch(cfavalue)
{
case "code1": id = "username1"; break;
case "code2": id = "username2"; break;
default: id = null; break;
}
ApplicationUser user = userManager.getUserByName(id as String) as ApplicationUser
return user

1 answer

0 votes
jpins March 19, 2019

Per: https://community.atlassian.com/t5/Answers-Developer-Questions/Script-Field-User-Picker/qaq-p/463717

 

You need to make sure Searcher is set to User Picker as well.

Suggest an answer

Log in or Sign up to answer