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

This widget could not be displayed.

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)
}
This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

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