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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

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

Auto Populate Multiselect custom field values based on single select list field value?

Hello All,

How to auto-populate Multiselect custom field values based on a single select list field value?

For Example -

We have a single select custom field Region with values EU, EAEU, and Mutliselect field with values Austria, Bulgaria, Spain, Poland.

If the user selects values called EU from the Region field it has to auto-select the following values Spain, Poland from Mutliselect field same way if user select value EAEU from Region field multi-select list field auto select to Austra and Bulgaria.

We have a script runner installed in our instance. 

Thanks in advance,

Manikanta

 

 

1 answer

1 accepted

0 votes
Answer accepted
Leo Community Leader Nov 02, 2020

Hi @manikanta ch ,

Below Behaviour snippet may give you some idea

 

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

@BaseScript FieldBehaviours fieldBehaviours

def multiSelectListName = 'MultiSelectList'
def region = getFieldByName("Region") as String

def selectField = getFieldByName(multiSelectListName)

def selectCustomField = customFieldManager.customFieldObjects.findByName(multiSelectListName)
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)

if (region == "EU") {
def defaultValue = selectAvailableOptions.findAll { it.value in ['Spain', 'Poland'] }
multiSelectListName.setFormValue(defaultValues*.optionId)
} else if (region == "EAEU") {
def defaultValues = selectAvailableOptions.findAll { it.value in ['Austra', 'Bulgaria'] }
multiSelectListName.setFormValue(defaultValues*.optionId)
}

 

Regards,

Leo

Thanks @Leo 

It worked with the below script

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

@BaseScript FieldBehaviours fieldBehaviours

def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

final singleSelectListName = 'Region'
final multiSelectListName = 'Countries'

def subRegField = getFieldByName(singleSelectListName)
def subRegion = subRegField.getValue()

def countriesField = getFieldByName(multiSelectListName)
def customField = customFieldManager.getCustomFieldObject(countriesField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def EUList = ['AUSTRIA', 'BULGARIA']
def gulfList = ['UNITED ARAB EMIRATES']
def EAList = ['REPUBLIC']
def optionsToSelect = []
if(subRegion == 'EU'){
optionsToSelect = options.findAll { it.value in EUList }
} else if(subRegion == 'GCC') {
optionsToSelect = options.findAll { it.value in gulfList }
} else if(subRegion == 'EAEU') {
optionsToSelect = options.findAll { it.value in EAEUList }
}
countriesField.setFormValue(optionsToSelect*.optionId)

Suggest an answer

Log in or Sign up to answer
TAGS

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