How to hide the field on Edit Screen

CST JIRA Confluence Admin September 25, 2016

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 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2016

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 {
    // ...
}
CST JIRA Confluence Admin September 26, 2016

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)
}
1 vote
Mark McCormack _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2016

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.

CST JIRA Confluence Admin September 26, 2016

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