Hi,
I need to show different values for same field based in the issue type.
From as I know, this can be done using Behaviors.
Jira Field:
Service and Sub-category - Is field is a cascade option.
Field options:
Service1 - 1 Sub 1
Service1 - 1 Sub 2
Service2 - 1 Sub 1
Service2 - 1 Sub 2
Service3 - 1 Sub 1
Service3 - 1 Sub 2
Context created:
Project = TESTSD
All issue types
What I need:
Issue type "Support"
must show only the options:
Service1 - 1 Sub 1
Service1 - 1 Sub 2
Service2 - 1 Sub 1
Service2 - 1 Sub 2
Issue type "BUG"
must show only the options:
Service3 - 1 Sub 1
Service3 - 1 Sub 2
Note 1 - this is to user in Service Desk
How can i do this? Can you help?
Thanks in advance
@Humberto Gomes, can you please clarify, should this be shown on the customer portal? Or is this on the agent side?
Thanks!
Kian
Hi,
Customer portal.
Humberto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Customer portal view:
Issue type mapping:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Humberto Gomes, I am looking into a solution!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Humberto Gomes,
Try something like this!
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customerSelectField = getFieldByName('Service and Sub-category')
def customField = customFieldManager.getCustomFieldObject(customerSelectField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionMap = [:]
optionMap.put("-1", "None")
if (issueContext.issueType.name == "Support") {
optionMap += options.findAll {it.value in ['Service1', 'Service2']}.collectEntries {[(it.optionId.toString()): it.value]}
}
else if(issueContext.issueType.name == "Bug"){
optionMap += options.findAll {it.value in ['Service3']}.collectEntries {[(it.optionId.toString()): it.value]}
}
customerSelectField.setFieldOptions(optionMap)
I did some testing with this and it appears to be working for me!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Kian Stack Mumo Systems Thanks for your time.
What i'm doing wrong here?
Behaviour:
Field options:
Mapping:
Code:
Service desk:
IF I Change the mapping to:
The problem is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmm. I'm not sure on that one. What version of Jira are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira Software 8.5.3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is the final code and it's working:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def issueType = issueContext.getIssueType().getName()
def cascadingCustomField = customFieldManager.getCustomFieldObjects().findByName("Service and Subcategory")
def cascadingFormField = getFieldByName("Service and Subcategory")
def fieldConfig = cascadingCustomField.getRelevantConfig(issueContext)
def options = optionsManager.getOptions(fieldConfig)
// Get the parent's ID
def parentA_ID = options.find
{ it.value == 'A' }
.getOptionId()
def parentB_ID = options.find
{ it.value == 'B' }
.getOptionId()
def parentC_ID = options.find
{ it.value == 'C' }
.getOptionId()
// Set the parent's options
Map option1 = [:]
option1.put ("-1", "None")
option1.putAll([(parentA_ID) : "A" , (parentB_ID) : "B"])
Map option2 = [:]
option2.put ("-1", "None")
option2.putAll([(parentC_ID) : "C"])
// Set available options based on Issue Type
if (issueType == "Bug")
{ cascadingFormField.setFieldOptions(option1) }
else if (issueType == "Support")
{ cascadingFormField.setFieldOptions(option2) }
Thanks for all support.
I'm tagging this as the Accept Answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
You can check out ScriptRunner's Library of the two below:
The idea of setting normal Select List or Cascading Select List field options are the same as given in the above links.
Other than that, do take note that there are two types of Behavior's mapping:
If you are trying to use it in Customer Portal, make sure you use the Service Desk mapping and map it to the appropriate Request Types.
Cheers~
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I find that these links you provided are done in Groovy. But we have some existing scripts written without groovy. Do i need to convert the whole script to groovy, or can i only convert this one line?
Or else can you tell me how to translate that before Groovy was being used in these scripts?
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.