My requirement is to create two multi select fields. Based on the values selected in the first field, the dropdown options of the second list needs to be populated.
The code is however not executing as expected and the values under the second dropdown are not getting populated dynamically.
My Code -
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import groovy.transform.BaseScript
import java.util.*
final CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def productsField = customFieldManager.getCustomFieldObject(25781)
log.debug("Inside Behaviour")
final String multiSelectProductsFamily = "Product Family"
final String multiSelectProducts = "Products"
def itProductFamily = getFieldByName(multiSelectProductsFamily).value;
List<String> itProducts = new ArrayList<>();
def product_1 = ['P1_Child1', 'P1_Child2', 'P1_Child3', 'P1_Child4'];
def product_2 = ['P2_Child1', 'P2_Child2', 'P2_Child3', 'P2_Child4'];
def product_3 = ['P3_Child1', 'P3_Child2', 'P3_Child3', 'P3_Child4'];
def product_4 = ['P4_Child1', 'P4_Child2', 'P4_Child3', 'P4_Child4'];
def product_5 = ['P5_Child1', 'P5_Child2', 'P5_Child3', 'P5_Child4'];
log.debug(itProductFamily)
for(product in itProductFamily){
switch(product){
case 'Parent_1':
itProducts.addAll(product_1);
case 'Parent_2':
itProducts.addAll(product_2);
case 'Parent_3':
itProducts.addAll(product_3);
case 'Parent_4':
itProducts.addAll(product_4);
case 'Parent_5':
itProducts.addAll(product_5);
}
}
log.debug(itProducts)
productsField.setFieldOptions(itProducts)
Please assist me in achieving the requirement. I am kind of very new to Jira administration.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
// Get a pointer to my select field
def itProductFamily = getFieldByName("Product Family")
def productFamily = getFieldByName("Products")
// Get pointers to the required custom field and otion managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customProductFamilyField = customFieldManager.getCustomFieldObject(itProductFamily.getFieldId())
def configProductFamily = customProductFamilyField.getRelevantConfig(getIssueContext())
def optionsProductFamily = optionsManager.getOptions(configProductFamily)
def customProductField = customFieldManager.getCustomFieldObject(productFamily.getFieldId())
def configProduct = customProductField.getRelevantConfig(getIssueContext())
def optionsProduct = optionsManager.getOptions(configProduct)
// If issue type matches change the cf values to be displayed
HashMap<String, String> map = new HashMap<>();
List lst = (List)itProductFamily.getValue()
if(lst.contains("Parent_1")) {
map.put("P1Child1", "P1Child1");
map.put("P1Child2", "P1Child2");
map.put("P1Child3", "P1Child3");
}
if(lst.contains("Parent_2")) {
map.put("P2Child1", "P2Child1");
map.put("P2Child2", "P2Child2");
map.put("P2Child3", "P2Child3");
}
if(lst.contains("Parent_3")) {
map.put("P3Child1", "P3Child1");
map.put("P3Child2", "P3Child2");
map.put("P3Child3", "P3Child3");
}
if(lst.contains("Parent_4")) {
map.put("P4Child1", "P4Child1");
map.put("P4Child2", "P4Child2");
map.put("P4Child3", "P4Child3");
}
if(lst.contains("Parent_5")) {
map.put("P5Child1", "P5Child1");
map.put("P5Child2", "P5Child2");
map.put("P5Child3", "P5Child3");
}
productFamily.setFieldOptions(map)
Found the solution but getting error that Invalid value 'P4Child3' passed for customfield ' Products'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.