Based on the country field, the type of activity field will display the corresponding values

Hi Team,
We have two single select fields, “Country” and “Type of Activity,” with predefined values. The requirement is that when a value is selected in the “Country” field, the “Type of Activity” field should display corresponding values. I have written a script to implement this functionality, but it is not working as expected. I would appreciate it if you could review the script and make any necessary corrections.

Furthermore, I would like to know if this requirement can be implemented in Jira. Please provide your feedback on whether Jira supports this functionality.

Thank you for your assistance.
Venkata Gopi

//import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
//import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

//import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
//import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl

import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager

import com.onresolve.jira.groovy.user.FieldBehaviours
def cfm = ComponentAccessor.getCustomFieldManager()
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField2 = cfm.getCustomFieldObject(12834)
def cfValue2 = issue.getCustomFieldValue(cField2).toString()

def cField3 = cfm.getCustomFieldObject(27000)
def cfValue3 = issue.getCustomFieldValue(cField2).toString()

/*def country = getFieldById("customfield_12834")
def typeOfActivity = getFieldById("customfield_27000")
def typeOfActivityCustomField = customFieldManager.getCustomFieldObjectByName("customfield_27000")
def countryvalue = country.getValue()
*/
def fieldConfig = typeOfActivitytCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null

if (cfValue2.toString() == "France") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Documents Upload", "Health benefits summary", "Health benefits ppt brochure", "Life & disability benefits summary", "Life & disability benefits ppt brochure", "Extraction of Claims Loss Ratio file", "Compilation of benefits", "Data entry in OMEGA file", "Managment indicators", "Mailbox administration", "E-mail archiving", "Affiliation form", "TPE administration", "TNS administration", "Extraction of premium data", "Creation of software accounts for Mercer employees", "Reset of software accounts for Mercer employees", "Modification of software accounts for Mercer employees", "Translation of Health benefits summary", "Translation of Health benefits ppt brochure", "Translation of Life & disability benefits summary", "Translation of Life & disability benefits ppt brochure", "Various translations", "GBMA", "Mercer Gold", "GBMA Email", "Creation of a mailing list", "Querry handling"]
}
}
else if (cfValue2.toString() == "Spain") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Member Mgmt - Change in a policy", "Manual request to insurance company", "Indra invoicmonthly upload", "Airbus monthly check", "GBMA", "Mercer Gold", "GBMA Email"]
}
}
else if (cfValue2.toString() == "Belgium") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["GBMA", "Mercer Gold", "GBMA Email"]
}
}
else if (cfValue2.toString() == "Netherland") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Registration and termination of employee", "Queri/ Claims", "Issuance of the Certificatof Coverage", "Member cost report"]
}
}
else if (cfValue2.toString() == "Switzerland") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["GBMA", "Mercer Gold", "GBMA Email", "Mailbox administration"]
}
}
else if (cfValue2.toString() == "Denmark") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Invoice handling", "Pension Advisory", "Querry handling", "Renewal reconciliation", "Visma Update", "Sending updates to providers"]
}
}
else if (cfValue2.toString() == "Norway") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Invoice handling", "Documents Upload", "Creating New Client", "MMB Platform Access", "Client Leaflet update","Renewal Support","GBMA","Mercer Gold","GBMA Email"]
}
}
else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Affiliation form", "Airbus monthly check", "Client Leaflet update", "Compilation of benefits", "Creating New Client", "Creation of a mailing list", "Creation of software accounts for Mercer employees", "Data entry in OMEGA file", "Documents Upload", "E-mail archiving", "Extraction of Claims Loss Ratio file", "Extraction of premium data", "GBMA", "GBMA Email", "Health benefits ppt brochure", "Health benefits summary", "Indra invoicmonthly upload", "Invoice handling", "Issuance of the Certificatof Coverage", "Life & disability benefits ppt brochure", "Life & disability benefits summary", "Mailbox administration", "Managment indicators", "Manual request to insurance company", "Member cost report", "Member Mgmt - Change in a policy", "Mercer Gold", "MMB Platform Access", "Modification of software accounts for Mercer employees", "Pension Advisory", "Query/ Claims", "Query handling", "Registration and termination of employee", "Renewal reconciliation", "Renewal Support", "Reset of software accounts for Mercer employees", "Sending updates to providers","TNS administration", "TPE administration", "Translation of Health benefits ppt brochure", "Translation of Health benefits summary", "Translation of Life & disability benefits ppt brochure", "Translation of Life & disability benefits summary", "Various translations", "Visma Update"]
}
}
applicationx.setFieldOptions(allowedOptions)

this is in jira service desk

I think you don‘t need to develop a script for this. It is a standard feature of Jira called cascading select. Creating dependent Cascading Lists in Jira Server/Datacenter | Jira | Atlassian Documentation

1 Like

Hi team,
No user wants to two different fields both are single select list fields. I have an app idea about cascade fields. I need for these two different fields.

Thank you,
Venkata gopi

The Atlassian user community is a better place for scripting advice: https://community.atlassian.com/

Adaptavist has clear, working examples of how to accomplish what you want, such as here: Set Behaviour Multi and Single Select Options and Value - Adaptavist Library

And finally, as Holger mentions, a Cascading select would be better because it just works out of the box with no code. You should rely on cascading select where possible. It lowers your maintenance burden.