import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def formField = getFieldByName("Closed Reasons") // update FIELD_NAME with your custom field name
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def Case = getFieldByName("Case Type")
// 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
if ( Case.getValue() == "Query")
{
def optionsMap = options.findAll {
it.value in ["User Management", "Password Reset", "Hierarchy Management", "Score Change", "Usability Query","Unsubscribe", "Additional Comments", "Customer could not find store/offer code", "Location Not Participating", "Data Import","Contact customer service/corporate #", "Duplicate","No Longer a Client", "Spam"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
}
else if ( Case.getValue() == "Error")
{
def optionsMap = options.findAll {
it.value in ["Link Error", "Survey Error", "Reporting Error", "Platform Error", "Platform Outage","Speed Issue (Reporting)", "Speed Issue (Platform)", "File Processor Error", "Survey Timed Out", "User Computer Error","User Error", "Customer Did Not Recieve Incentive","Incorrect Information", "Spam","Survey Automatically Submitted","Coupon/Sweep Questions", "Duplicate", "No Longer a Client"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
}
else if (Case.getValue() == "Appeal")
{
def optionsMap = options.findAll {
it.value in ["Appeal Approved", "Appeal Declined", "Raised In Error", "Duplicate", "No Longer a Client","Spam"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
}
else if (Case.getValue() == "Change Request")
{
def optionsMap = options.findAll {
it.value in ["Change Requested", "Change Actioned", "Change Denied", "Duplicate", "No Longer a Client","Spam"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
}
else if (Case.getValue() == "PII Request ")
{
def optionsMap = options.findAll {
it.value in ["GDPR Request Completed", "CCPA PII Request Completed", "Email Not Verified", "Duplicate","Spam"]
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
formField.setFieldOptions(optionsMap)
}
else
{
}
For your requirement, I would suggest using a Server-Side Behaviour for the first list, which will determine the filter for the second list.
Below is a print screen of the Behaviour configuration:-
Below is the sample code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()
def list2 = getFieldByName("List 2")
def optionManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def list2CustomField = customFieldManager.getCustomFieldObject(list2.fieldId)
def list2Config = list2CustomField.getRelevantConfig(issueContext)
def list2Options = optionManager.getOptions(list2Config)
def listBNewOptions
if(list1Value == "Zone 1") {
listBNewOptions = ["USA", "Canada", "Mexico", "Brazil", "Argentina"]
} else if(list1Value == "Zone 2") {
listBNewOptions = ["UK", "Germany","Sweeden","UAE"]
} else if(list1Value == "Zone 3") {
listBNewOptions = ["India", "Malaysia","Singapore", "Thailand"]
} else {
listBNewOptions = ["USA", "Canada", "Mexico", "Brazil", "Argentina", "UK", "Germany","Sweeden","UAE", "India", "Malaysia","Singapore", "Thailand"]
}
def listBNewOptionsMap = [null: "None"]
listBNewOptionsMap += list2Options?.findAll {
it.value in listBNewOptions
}?.collectEntries {
[ (it.optionId.toString()) : it.value ]
}
list2.setFieldOptions(listBNewOptionsMap)
Please note, this sample code is not 100% exact to your environment. Hence you will need to modify it accordingly.
If you notice in the code I am using:-
def list1 = getFieldById(fieldChanged)
It ensures that the behaviour will trigger only if the first list, i.e. List 1, is updated. In this case, whenever the option in List 1 is updated, List 2 will update accordingly.
Below are a few test print screens:-
First, when no option is selected from List 1, i.e. None, List 2 will display all the options as shown below.
If the option in List 1 is updated to Zone 1, List 2 will only show the options associated with Zone 1, as shown below.
If the option in List 1 is updated to Zone 2, List 2 will only show the options associated with Zone 2, as shown below.
And finally, if the option in List 1 is updated to Zone 3, List 2 will only show the options associated with Zone 3, as shown below.
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_ - Thank you. Does this work when the second dropdown is later in the workflow ? / on a pop up screen when the issue is being transitioned.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ - Also the first field isn't on the create screen but part fo the workflow as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To clarify, are both the First List and Second List on the same transition screen?
If so, you can use the same code with a minor modification, i.e. include an additional if condition outside as shown below:-
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()
def list2 = getFieldByName("List 2")
def optionManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def list2CustomField = customFieldManager.getCustomFieldObject(list2.fieldId)
def list2Config = list2CustomField.getRelevantConfig(issueContext)
def list2Options = optionManager.getOptions(list2Config)
def listBNewOptions
if(actionName == "The Transition Screen Name") {
if(list1Value == "Zone 1") {
listBNewOptions = ["USA", "Canada", "Mexico", "Brazil", "Argentina"]
} else if(list1Value == "Zone 2") {
listBNewOptions = ["UK", "Germany","Sweeden","UAE"]
} else if(list1Value == "Zone 3") {
listBNewOptions = ["India", "Malaysia","Singapore", "Thailand"]
} else {
listBNewOptions = ["USA", "Canada", "Mexico", "Brazil", "Argentina", "UK", "Germany","Sweeden","UAE", "India", "Malaysia","Singapore", "Thailand"]
}
def listBNewOptionsMap = [null: "None"]
listBNewOptionsMap += list2Options?.findAll {
it.value in listBNewOptions
}?.collectEntries {
[ (it.optionId.toString()) : it.value ]
}
list2.setFieldOptions(listBNewOptionsMap)
}
Else, if they are in two different transition screens, the behaviour only may not be the best approach.
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you explain, why you don't use simple cascading options?
I can imagine that the reason got lost at simplifying the problem. On the other hand this possibility would be much easier than using scriptrunner if it fulfills your requirements.
Regards
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.
working script ,, use behaviour..
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("Testing Field")
def typeOfEngagement = getFieldByName("Client")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Client")
def verticalValue = vertical.getValue()
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (verticalValue.toString() == "A"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Google", "Microsoft"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Yahoo"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly close allowed option at end with )
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.