You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Garden16_ I'd just add something like
else if(!selectListValues || selectListValues.isEmpty()) {
fieldA.setHidden(true)
fieldB.setHidden(true)
fieldC.setHidden(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.