Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit a custom field values in customer portal in Particular group in Request type

Deleted user December 19, 2019

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

 

 

1 answer

0 votes
Leo
Community Champion
December 19, 2019

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

Deleted user December 20, 2019

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events