Forums

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

dynamic display a single select list base on issue type

ClaireYang
Contributor
May 6, 2019

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!

2 answers

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 9, 2019

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

ClaireYang
Contributor
May 9, 2019

Thank you Antonie!!!!! It works perfectly!

Like Antoine Berry likes this
Brian March 23, 2020

So now how would you do this in a JIRA Cloud instance?

0 votes
SWAPNIL SRIVASTAV
Contributor
November 3, 2019

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

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 4, 2019

Hi @SWAPNIL SRIVASTAV ,

If you follow the logic of the script, the optionsMap being empty either means that : 

  • the issuetype is not in the first switch list
  • the values defined in the "map" are not valid for the select custom field (remember that it is case sensitive)

Antoine

SWAPNIL SRIVASTAV
Contributor
November 4, 2019

Hello @Antoine Berry ,

Here's my original request:

https://community.atlassian.com/t5/Jira-questions/Is-it-possible-to-have-a-scripted-select-list-which-contain/qaq-p/1211810#U1218384

or

https://community.atlassian.com/t5/Jira-questions/How-to-add-dynamic-options-into-a-Select-List-custom-field-using/qaq-p/1217509

(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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events