Hello
I have applied some custom picker fields (e.g. user picker for a specified group) with script runner.
Is it possible to use setFieldOptions of behaviour to restrict the selections to a smaller scope ?
Hi @Yin Liang_XDevPod
If you are using a Custom Picker field, setting the field options via Behaviour is not feasible as this is controlled by the configuration you have set for the Custom Picker.
Since you intend to create a custom field based on the User's Group, why not just use Behaviour to convert a Text Field to a List and pull the options from the REST Endpoint? You'll have more control and can filter the options accordingly from there.
I have given a similar solution in this Community Post some time back.
The sample provided in the Community Post is filtering the users by User Role. You will need to modify it to filter it by Group instead.
Thank you and Kind regards,Ram
Hey @Yin Liang_XDevPod ,
Yes, that would be possible. There are some existing samples here which you can use as reference:
Hope it helps.
Sean
@Sean Chua _Adaptavist_
Thank you very much for your quick answer.
The filed to "setFieldOptions" is not system fields or custom select field, it's the "Custom Picker" filed created via script runner.
Pls see below code for the picker
import com.atlassian.jira.component.ComponentAccessorimport com.onresolve.scriptrunner.canned.jira.fields.model.PickerOptionimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.user.util.UserManagerimport com.atlassian.crowd.embedded.api.Groupimport com.atlassian.jira.avatar.Avatardef groupManager = ComponentAccessor.getGroupManager()def userManager = ComponentAccessor.getUserManager()def avatarService = ComponentAccessor.avatarServicedef authenticationContext = ComponentAccessor.jiraAuthenticationContextdef group = groupManager.getGroup("team1")def users = group.getMembers()search = { String inputValue ->return users}getItemFromId = {String id ->userManager.getUserByKey(id)}toOption = { ApplicationUser user, Closure<String> highlight ->def remoteUser = authenticationContext.getLoggedInUser()new PickerOption(value: user.key,label: user.name,html: highlight(user.displayName, false),icon: avatarService.getAvatarURL(remoteUser, user, Avatar.Size.SMALL)?.toString())}
how to set options for such field ? what's the input parameter for setFieldOptions()?
Hey Yin Liang,
Thanks for the callout and I do apologise for reading the question wrongly - I must have been groggy from not having my morning coffee yet. It is as what you and ram has pointed out.I would have gone with Ram's suggestion to use a Text field which is also feasible and he also shared his solution;
I have given a similar solution in this Community Post some time back.The sample provided in the Community Post is filtering the users by User Role. You will need to modify it to filter it by Group instead.
Regards,Sean
It looks like you're new here. Sign in or register to get started.