Hello All,
We have created different Groups(1, 2, 3) in Service desk project Request types and Group 1 and Group 2 has a custom field called Tools with options Jira, Confluence, & Bitbucket.
In custom portal if customer selects a Group 1, Tools custom field should display only Jira and confluence options if he selects Group 2 it has to display only Jira and Bitbucket options.
To achieve this i have added below script in the behavior. But it is restricting values to all groups in the Request type. i am new to groovy script.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def formField = getFieldByName("Tools") // update FIELD_NAME with your custom field name
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
// update below OPTION_ONE, OPTION_TWO, OPTION_THREE with desired options
// note the options listed need to first be configured within the full project field context and must match exactly
def optionsMap = options.findAll {
it.value in ["Jira", "Confluence", "Bitbucket"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
Please help!
Thanks in advance,
Ch
Hi @[deleted],
It looks like you are not validating currentUser's group. I haven't tried the below code in my project though, it may require some minor changes
I assume Group-1 & Group-2 are not custom field values
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.customfields.option.Option def issueField = getFieldByName("Tools") // Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def customField = customFieldManager.getCustomFieldObject(issueField.fieldId) def config = customField.getRelevantConfig(getIssueContext()) // Get predifined customField options
def options = optionsManager.getOptions(config) def groupProjectsMap = [ 'Group-1': ['Jira','BitBucket','Confluence'], 'Group-2': ['Jira','BitBucket'], ] def optionsToSet = [] log.debug("Map: ${groupProjectsMap}") for (r in groupProjectsMap) { if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find {it.name == r.key }) { def option = options.findAll {it.value in r.value} as List<Option> optionsToSet.add(option) } } log.debug("Options: ${optionsToSet.flatten()}") issueField.setFieldOptions(optionsToSet.flatten())
BR,
Leo
Hi @Leo
Thanks for the script!
Actually i am looking for Request Type Groups not User Groups. Is there any way to read request Type Group in Jira service Desk behaviour.
Please help!
Thanks in advance,
ch
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.