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

Accepted Answer
0 votes

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
Community showcase
Posted Tuesday in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

35 views 0 2
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