Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

dynamic display a single select list base on issue type

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 May 09, 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

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

Like Antoine Berry likes this

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

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 Nov 04, 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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

269 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you