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 ?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.avatar.Avatar
def groupManager = ComponentAccessor.getGroupManager()
def userManager = ComponentAccessor.getUserManager()
def avatarService = ComponentAccessor.avatarService
def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def 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()?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline 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.