Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Making custom field mandatory based on another field

Piotr Nowak June 10, 2019

Hello,

I want to make custom field mandatory when another custom field has a specific value. I want to make it via JMWE groovy script validator on issue creation page.

I wrote something like below: 

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def selectCFValue = customFieldManager.getCustomFieldObjectByName("Issue Source")
def selectedValue = issue.getCustomFieldValue(selectCFValue)
def targetField = customFieldManager.getCustomFieldObjectByName("SSF Models")

if (selectedValue.equals("PLM")) {
targetField.setRequired(true)}
else {
targetField.setRequired(false)}

But I have an error message that:

Message:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.setRequired() is applicable for argument types: (java.lang.Boolean) values: [false]
Stack:
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
script15601655936021417005859.run(script15601655936021417005859.groovy:9)

without "else" the script test was positive and on creation page for all "Issue source" value "SSF Models" field is always required. 

Anyone can help me with that?

0 answers

Suggest an answer

Log in or Sign up to answer