I'm trying to make a 'User Picker' field.
import com.atlassian.jira.avatar.Avatar
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserFilter
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def userManager = ComponentAccessor.userManager
def avatarService = ComponentAccessor.avatarService
def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def groupManager = ComponentAccessor.groupManager
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def groups = groupManager.getGroupNamesForUser(currentUser)
ArrayList<String> resGroups = []
def mLen = 255
def aGroup = ""
for(group in groups){
if(group.indexOf("something")==-1){
if(group.length() <= mLen ){
mLen = group.length()
aGroup = group
}
}
}
if(aGroup!="") resGroups.add(aGroup)
def userFilter = new UserFilter(true, null, resGroups)
def userSearchParams = new UserSearchParams.Builder().allowEmptyQuery(true).filter(userFilter).maxResults(30).build()
search = { String inputValue ->
userSearchService.findUsers(inputValue, userSearchParams)
}
getItemFromId = { String id ->
userManager.getUserByKey(id)
}
renderItemViewHtml = { ApplicationUser user ->
user.displayName
}
renderItemTextOnlyValue = renderItemViewHtml
toOption = { ApplicationUser user, Closure<String> highlight ->
def remoteUser = authenticationContext.loggedInUser
new PickerOption(
value: user.key,
label: user.displayName,
html: highlight(user.displayName, false),
icon: avatarService.getAvatarURL(remoteUser, user, Avatar.Size.SMALL)?.toString()
)
}
Is there a way to create a field that filters the value of the list differently for each user (the logged-in user)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.