Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,534
Community Members
 
Community Events
165
Community Groups

Hide custom fields based on drop down selection

I have a custom field that  displays User story   and Epic  (Issue type 1 and Issue type 2)

This custom field is multi issue search picker. I have created this field using the scripted field in Script runner.

I have custom Field A, Field B and Field C which have to be displayed based on the issue type selected in the drop down custom field  - User story and Epic(Issue type 1 and Issue type 2) 

If issue type 1 (user story) is selected from the drop down then the other custom fields A,B , C have to be displayed . If I select Issue type 2 (epic) the custom fields A,B , C should not be displayed .

 

How do I achieve it using script runner behavior code 

2 answers

I am able to  hide   Field A, Field B and Field C  when the no issue type gets selected from the drop down. If I select  on or the other issue type then the Reminder fields   Field A, Field B and Field C are getting displayed.

I want  Field A, Field B and Field C to be displayed only when I select User story  issue type  from the drop down.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger


def fieldA = getFieldById("customfield_12801")
def fieldB= getFieldById("customfield_10400")
def fieldC= getFieldById("customfield_12800")


def selectList = getFieldById("customfield_11508")
def selectListValue = selectList.value


//If there is no value, do nothing and if issue type selected is Epic - Hide other fields.
if (!selectListValue || selectListValue == "Epic") {
fieldA.setHidden(true)
fieldB.setHidden(true)
fieldC.setHidden(true)

}

else{
fieldA.setHidden(false)
fieldB.setHidden(false)
fieldC.setHidden(fasle)
}

 am able to  hide   Field A, Field B and Field C  when the no issue type gets selected from the drop down. If I select  on or the other issue type then the Reminder fields   Field A, Field B and Field C are getting displayed.

I want  Field A, Field B and Field C to be displayed only when I select User story  issue type  from the drop down.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger


def fieldA = getFieldById("customfield_12801")
def fieldB= getFieldById("customfield_10400")
def fieldC= getFieldById("customfield_12800")


def selectList = getFieldById("customfield_11508")
def selectListValue = selectList.value


//If there is no value, do nothing and if issue type selected is Epic - Hide other fields.
if (!selectListValue || selectListValue == "Epic") {
fieldA.setHidden(true)
fieldB.setHidden(true)
fieldC.setHidden(true)

}

else{
fieldA.setHidden(false)
fieldB.setHidden(false)
fieldC.setHidden(fasle)
}

Any code Suggestion's Please

Hi @Garden16_ Adaptavist is publishing snippets of the code for a lot of use cases. I found something what you can use to start with scripting.

https://library.adaptavist.com/entity/set-form-field-values-from-issue-in-picker

  • it is based on the issue picker
  • relatedIssue variable stores the issue in picker

There is another snippet which shows you how to hide the field

https://library.adaptavist.com/entity/set-behaviour-hidden

 

Let me know if you need more information.

Hi @Garden16_ , I tried to fix your script. It is not exactly the same as you need but it should give you more information...

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger


def fieldA = getFieldById("customfield_10001")


def selectList = getFieldByName("Issues to pick")
def selectListValues = selectList.value

def epicSelected = selectListValues.any{ it ->
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(it as String)
return issue.issueType.name == "Epic"
}


if (epicSelected) {
fieldA.setHidden(true)
}

else{
fieldA.setHidden(false)
}

Thank you so much  .This worked !! :)

 

But just one more thing , what about the following  conditions. I had it in my code before. But now its not working

1: If nothing is selected form the drop down or if it blank  if (!selectListValue ) is  null then hide the Fields A,B & C

Hi @Garden16_ I'd just add something like 

else if(!selectListValues || selectListValues.isEmpty()) {
fieldA.setHidden(true)
fieldB.setHidden(true)
fieldC.setHidden(true)
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Improving the Create Issue Experience in Jira Service Management Cloud

Hello everyone!  We are very excited to announce some much needed changes to the issue create experience in JSM (the blue "create" button) at the top of the screen.  We have just starte...

177 views 7 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you