Forums

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

Subcategory values are to be dependent on Category and both required

Silvia Goljerova December 27, 2018

Hi, 

I'm working in JSD and would like both Category (Hardware, Software,  Network, etc) and Subcategory (Mouse, Disk, Harvest, Jira, VPN, etc.) to be required (easy, I got this part using configuration).  I would with only like certain values to be available for selection in Subcategory when a Category value is chosen. Unfortunately, Select List (cascading) won't work, as when it's made required, the condition is satisfied with only a single value selected.  In other words, it's ok with the user only selecting 'Software', but not the subcategory value.  

I have just installed ScriptRunner in hopes of a fast solution, but as I'm a complete novice to it, it's quite a challenge.  Your suggestions would be much appreciated!

 

Thanks!

1 answer

1 accepted

2 votes
Answer accepted
Silvia Goljerova December 28, 2018

Just in case anyone's checking.  I got it figured out based on someone else's post (which I unfortunately lost).  Add the following to Server script to the Category field:

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.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def typeofSubcategoryCustomField = customFieldManager.getCustomFieldObjectByName("Product Subcategory")
def fieldConfig = typeofSubcategoryCustomField.getRelevantConfig(issueContext)
def category = getFieldByName("Product Category")
def categoryValue = category.getValue()
def typeOfSubcategory = getFieldByName("Product Subcategory")

if (categoryValue.toString() == "Hardware"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["None","Mouse", "Monitor", "CPU"]
}
}
else if (categoryValue.toString() == "Network") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["None","VPN", "IP Address","Wireless"]
}
}
else if (categoryValue.toString() == "Software") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["None","Ticketing (Siebel)", "Ticketing (Jira Service Desk)","Time tracking (Harvest)","Billing (Kenan)","Billing (GBS)"]
}
}
else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["None","VPN", "IP Address"]
}
}
typeOfSubcategory.setFieldOptions(allowedOptions)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events