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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.