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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,551,823
Community Members
 
Community Events
184
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

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

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.
Apr 04, 2022

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
AUG Leaders

Atlassian Community Events