Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Hide custom fields based on drop down selection

Garden16_ March 25, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Garden16_ March 29, 2022

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)
}

Garden16_ March 29, 2022

 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)
}

Garden16_ March 29, 2022

Any code Suggestion's Please

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2022

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.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2022

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)
}
Garden16_ March 29, 2022

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

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2022

Hi @Garden16_ I'd just add something like 

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

Atlassian Community Events