The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Scriptrunner: Dynamic select not working for Portal Forms and Project "Create Issue" screens

Sami Ahmed Shaik
Contributor
August 9, 2021

Hello there,

I am trying to achieve the dynamic select. Consider the following CFs and scenario.

Custom Fields:

Category (Select List)

  • Backup
  • Database

Subcategory (Select List)

  • Backup Server
  • Backup Software
  • Oracle Database
  • SQL Database

Scenario:

Consider user selects the "Backup" from the category, based on the selection, Subcategory should display "Backup Server" & "Backup Software" values.

 

I am using the following script using BEHAVIOURS

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final singleSelectName = 'Category'
final selectName = 'Subcategory'

def cfManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def singleSelectField = cfManager.getCustomFieldObjectsByName(selectName)[0]
def formSingleSelect = getFieldByName(singleSelectName)
def singleSelectValue = formSingleSelect?.value
def formSelect = getFieldByName(selectName)

// Make sure the fields we want to work with are on the form
if (!formSingleSelect && !formSelect) {
return
}

// Must grab the relevant config given the current issue context and the custom field
def config = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(issueContext, singleSelectField)
// Given config, grab a map of the possible options for the second select custom field
def options = optionsManager.getOptions(config)

// Define your preset options for each single select case using the format shown here.
// Just put the values, not the keys/IDs.
def optionSet1 = [
"Oracle Database",
"SQL Database"
]
def optionSet2 = [
'Backup Software',
'Backup Server'
]


// Make sure the second field actually has options to set
if (!options) {
return
}

// Set/use the appropriate optionSet, dependent on the value of the currently selected single select option
switch (singleSelectValue) {
// Notice: The optionSet that is used is changed in each case
// Change 'Single Select Option...' to match your single select's values.
case "Database":
formSelect.setFieldOptions(options.findAll { it.value in optionSet1 }.collectEntries {
[(it.optionId): it.value]
})
break
case "Backup":
formSelect.setFieldOptions(options.findAll { it.value in optionSet2 }.collectEntries {
[(it.optionId): it.value]
})
break

// Reset to default options if single select option is null or any other option that is not taken care of
default:
formSelect.setFieldOptions(options)
}


 

Above script is not working, please help me in this regards.

 

Thanks,

Sami Ahmed Shaik.

 

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Sami Ahmed Shaik
Contributor
August 16, 2021

Got it working after restarting the jira instance.

0 votes
Leo
Community Champion
August 12, 2021

Hi @Sami Ahmed Shaik

I don't see any issue with script. Have you done with servicedesk project mapping with request types instead of issue types?

 

Regards,

Leo

TAGS
AUG Leaders

Atlassian Community Events