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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,270 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot