Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • Restricting the values in multiselect field based on the options selected in another multiselect

Restricting the values in multiselect field based on the options selected in another multiselect

Pratibha Tambakad November 16, 2022

Hello Team,

We have three fields

Country Specificity- Single select list

Region - Multiselect field

Country- Multiselect field

Requirement1 -Based on the values selected in field Country specificity ,The field region should become Reaonly or editable 

Ex :if Country specificity is selected as Global then Region field should be Readonly and Country specificity values is changed to Local then Region field should be enabled & editable

Requirement2- Based the values selected in Region Multiselect field the values should be restricted in field Country

Ex: If Region is set 'Asia Pacific' then Country field should populated the values which are relevant to only 'Asia pacific' remaining values should be hidden.

Below script I used to achieve this. Please check the script and help me to achieve this:

and also getting the error '[Static type checking] - No such property: optionId for class: java.util.List <?>'

when i clicked on the line and on the property optionId "countriesField.setFormValue(optionsToSelect*.optionId)"

 

Find the script below:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.util.List
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

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

final singleSelectListName = 'Country Specificity'
final multiSelectListName = 'Region'
final multiSelectCountry = 'Country'


//country specificity
def countryspecificity = getFieldByName(singleSelectListName)
def countryspecificityvalue = countryspecificity.getValue()

//region
def regionField = getFieldByName(multiSelectListName)
def regionFieldFieldValue = regionField.value as List

//country
def countriesField = getFieldByName(multiSelectCountry)
def customField1 = customFieldManager.getCustomFieldObject(countriesField.getFieldId())
def config1 = customField1.getRelevantConfig(getIssueContext())
def options1 = optionsManager.getOptions(config1)

if(countryspecificityvalue == 'Global')
{
   regionField.setReadOnly(true)
}
else if(countryspecificityvalue == 'Local')
{
   regionField.setReadOnly(false)
}
//Defining the Country values in a array
def CountryList = ['Guam', 'Japan']
def CountryList1 = ['Australia', 'American Samoa']
def optionsToSelect = []

if(regionFieldFieldValue == ['Asia Pacific'])
{
optionsToSelect = options1.findAll { it.value in CountryList }
}
else if(regionFieldFieldValue==['Latin America'])
 {
optionsToSelect = options1.findAll { it.value in CountryList1 }
}
countriesField.setFormValue(optionsToSelect*.optionId)

 

0 answers

Suggest an answer

Log in or Sign up to answer