Scripted Field - How to return multiple users

Josh_Kochelek__Modus_Create
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2019

Hello!

I am working on a scripted field that returns one or multiple users, based on the value of another custom field (multi-select list). When I preview the script with an appropriate issue key, the results display perfectly. However, when I look at the issue, there is no value in the field. 

The field is present on the appropriate screens and configured for the project / issue type. I feel like I'm close , but is there something I'm missing here? Any help here would be much appreciated.

Here's my code:

import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue


def list1 = ["1","2","3"]
def list2 = ["4","5","6"]

def user1 = ComponentAccessor.getUserManager().getUserByName('user1')
def user2 = ComponentAccessor.getUserManager().getUserByName('user2')

def customFieldManager = ComponentAccessor.customFieldManager
def customFieldName = "Group ID"
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
def customFieldVal = issue.getCustomFieldValue(customField) as List
def cmList = []

customFieldVal.each { it ->
if ( list1?.contains(it.toString())) {
cmList.addAll(user1)

}
if ( list2?.contains(it.toString())) {
cmList.addAll(user2)
}
}
if (cmList == null) {return "custom field not found"}
if (cmList != null) {return cmList}

  

1 answer

1 accepted

1 vote
Answer accepted
Josh_Kochelek__Modus_Create
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2019

Figured this out, finally! The issue was the custom field search template was set up as the default 'Free Text Searcher'. Once I changed it to 'Multi User Picker Searcher' the field started working as expected. 

I found the solution in comments from @Ivan Tovbin (thank you!) here: Scripted Custom Field User Picker Template always return Anonymous in Jira 8

After you do that, you need to set the correct searcher (search template)  for your field.

Go to Admin > Issues > Custom Fields, find your field there and then click on the 'gear' icon to the right. In the opened menu click on "Edit". In the next screen select "User Picker searcher" in the "Search Template" field.

More info on configuring your custom fields can be found in this documentation.

Suggest an answer

Log in or Sign up to answer