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
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)
}
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.