Hi All
We recently created two custom fields, one is a single field (company name), and the other is a multi-selected field (contact). We hope that when we create a question, after selecting the corresponding company name, the contact field will only show the contacts of that company, not all of them.
I have learned that Script Runner for Jira can do this in the Behaviour. I have tried several times, but I find that I can't get corresponding custom fields and assign values. Can you help me implement this function,thanks.
Hi @arno ,
Welcome to Atlassian community !!
Yes, you can configure this using script runner Behaviors. Here is the sample script, considering two select list:
Replace correct field id customfield_XXX1, customfield_XXX2 in code:
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.*
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def firstField = getFieldById("customfield_XXX1")
def firstFieldSelectedValues = firstField.value as List
def secondField = getFieldById("customfield_XXX2")
HashSet<String> selectedOptions=new HashSet();
for (option in firstFieldSelectedValues) {
def optionName = option.toString();
if(optionName.trim().equalsIgnoreCase("A")){
selectedOptions.addAll(new HashSet<String>(Arrays.asList("A1", "A2", "A3")));
}
if(optionName.trim().equalsIgnoreCase("B")){
selectedOptions.addAll(new HashSet<String>(Arrays.asList("B1", "B2", "B3")));
}
if(optionName.trim().equalsIgnoreCase("C")){
selectedOptions.addAll(new HashSet<String>(Arrays.asList("C1", "C2")));
}
}
if (firstFieldSelectedValues != [null] && selectedOptions.size() > 0) {
secondField.setFieldOptions(selectedOptions)
}
Hope this helps !!
Hi @Deepak Jain
Thank you for your reply
I have tried according to your method, but found no effect. Is there a problem with my configuration? Below is the screenshot of my Settings and the final effect display
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.