Forums

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

Filter field

arno
Contributor
June 24, 2023

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.

1 answer

0 votes
Deepak Jain
Community Champion
June 24, 2023

Hi @arno ,

Welcome to Atlassian community !!

Yes, you can configure this using script runner Behaviors. Here is the sample script, considering two select list:

  • First Field - A, B C
  • Second Field - A1, A2, A3, B1, B2, B3, C1, C2

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 !!

arno
Contributor
June 24, 2023

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

field setting.pngfield.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events