How to hide the field on Edit Screen

We have 1 ScriptRunner scripted field. We want to hide 2 JIRA custom fields on Edit Screen based on the logic:

if scripted = value a

  • show custom field 1 and make it mandatory
  • show custom field 2 and make it mandatory

else

  • hide custom field 1
  • hide custom field 2

We've tried Behaviour function from ScriptRunner but no luck. Please advise.

2 answers

1 accepted

0 vote

Scripted fields are calculated fields, so can't be edited, so will never appear on a screen.

Therefore you can't get the value from behaviours, but you can get it from the java API for the issue.

Eg:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Some Scripted Field")
def cfValue = underlyingIssue?.getCustomFieldValue(cf)

if (cfValue == "foo") {
    getFieldById("summary").setRequired(true)
    // etc
}
else {
    // ...
}

Great. It works. Thanks a lot.

Here is my code

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("MJE, IC, CAPEX")
def cfValue = underlyingIssue?.getCustomFieldValue(cf)
if (cfValue == "Capex") {
    getFieldByName("Target Go Live Date").setRequired(true)
    getFieldByName("Project id").setRequired(true)
    getFieldByName("Target Go Live Date").setHidden(false)
    getFieldByName("Project id").setRequired(false)
}
else {
    getFieldByName("Target Go Live Date").setHidden(true)
    getFieldByName("Project id").setHidden(true)
}

Hi, I'd recommend taking a look at our article in the documentation that shows how to make a field mandatory or hidden based on the value of another select list field. It should help you get a long way towards configuring Behaviours to do this.

regards, Mark.

Hi Mark,

I've read the document on ScriptRunner carefully but it seems that it cannot work with scripted field. It only can be done by JIRA custom field (select list ...). Is it correct?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

169 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you