Hi there,
We have a single select list named "service category", which has many options. And I hope it can be dynamic displayed base on issue type value when user submit or edit issues.
For example, when user submit case and choose issue type A, the "service category" field only show A,B and C options. But when user choose issue type B, the field will show other options D and E. I hope it can also work when user edit issue type and "service category" field in a existed issue.
I know it can be done by Behaviours, but I'm a script newbie, could someone tell me how to write the script?
Thank you very much!
Hi @ClaireYang ,
Please create a behaviours and map it to the "Issue Type" field. Then please try to use this script :
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int selectListId = 11001
def selectList = getFieldById("customfield_" + selectListId)
String issuetype = getIssueContext().getIssueType().getName()
def map
switch (issuetype){
case "Incident":
map = ["Value 1", "Value 2"]
break;
case "Task":
map = ["Value 3", "Value 4"]
break;
default :
break;
}
if (map != null){
def optionsManager = ComponentAccessor.getOptionsManager()
def selectListCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(selectListId)
def fieldConfig = selectListCustomField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(fieldConfig)
def optionsMap = options.findAll {
it.value in map // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
selectList.setFieldOptions(optionsMap)
}
Update the id of the select list custom field, the values of the issue types the select list values.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Antoine Berry and @ClaireYang ,
I tried the same script. But I am getting an error in the last line.
setFieldOptions method is not working. Error:
Cannot Find Matching method.
groovy.lang.MissingMethodException : No signature of method :
com.atlassian.jira.issue.fields.ImmutableCustomField.setFieldOptions() is applicable for argument types: (java.util.LinkedHashMap) values: [[:]]
Could you please help
Thanks and Regards,
Swapnil Srivastav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @SWAPNIL SRIVASTAV ,
If you follow the logic of the script, the optionsMap being empty either means that :
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Antoine Berry ,
Here's my original request:
or
(Here, I have mentioned the code that I have used).
Kindly have a look and let me know, where am I going wrong.
Thanks and Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.