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}
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.