Forums

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

How make two custom fileds (multi select list) required based on custom field value selection?

Bunty
Contributor
February 13, 2019

Hello All,

How to make two custom fields required (multi select list) based on the custom field value selection??

Example:

we have a custom field called "Class"(single select list) , "Branding"(multi select list) and  "Docs"(Multi select list). 

If class selected with the value "Output", Branding and Docs custom fields should be required on the create screen.

I have added two simple scripted validators on the create transition.

1. cfValues['Class']?.value != 'Output' || cfValues['Branding']

2 . cfValues['Class']?.value != 'Output' || cfValues['Docs']

It is working only for Branding custom field and for Docs it is showing required field but after selecting value in that issue is not creating and it showing "Docs field is required".

Any help would be greatly appreciated!!

Thanks in Advance,

Bunty

1 answer

1 accepted

0 votes
Answer accepted
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2019

Hello,

Indeed, a scripted validator is the solution. Here's the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException

String classValue = getCustomFieldValue(issue, "Class")?.getValue()
List<LazyLoadedOption> brandingValue = getCustomFieldValue(issue, "Branding")
List<LazyLoadedOption> docsValue = getCustomFieldValue(issue, "Docs")

if (classValue.equals("Output") && (!brandingValue || !docsValue)){
throw new InvalidInputException("Branding and Docs are required!")
}
return true

Object getCustomFieldValue(Issue issue, String fieldName){
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName)
return issue.getCustomFieldValue(customField)
}
Bunty
Contributor
February 15, 2019

Thank you @Ivan Tovbin 

Suggest an answer

Log in or Sign up to answer