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
Hi,
I have an assets / insight based custom field B that is filtered via IQL based on the value in assets/insight based custom field A. So far so good. This all works. But sometimes there aren't any possible values in field B if field A has a certain value. If that is the case I would like to hide customfield B.
I now want to check in a groovy script what all the possible values for field A are.
I think that when I run the script and field A is empty , the result of the possible options should be empty and if field A has a value, the result should be the result of the IQL query.
I have searched the community, but for now have not been able to come up with something. I found this article to get possible values of multiselect custom field, but when I run that script with correct parameters of my issue and field id it doens't give me any results :
https://community.atlassian.com/t5/Jira-questions/scriptrunner-how-to-get-possible-values-of-multiselect-custom/qaq-p/1363489
Doe anyone have an idea ?
This is the domain of Scriptrunner Behavious. Do you have access to that app?
If not, I'm not aware of any other way to conditionally show/hide a field like you suggested.
If you have scriptrunner, then it's a simple matter of picking up changes in field A, then constructing an IQL query with the selected value (the IQL must match the IQL you use in the field B configuration) and if the IQL returns no results, then set field B to hidden.
Something like this:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def fieldA = getFieldByName('Customer(s)')
def fieldB = getFieldByName('B')
def fieldAValue = fieldA.value
def iql = """objectType = "object type for field b" and "field A attribute" = $fieldAValue"""
def searchResults = Assets.search(iql)
def showFieldB = searchResults.size() > 0
fieldB.setHidden(!showFieldB)
I have access to Scriptrunner and was planning on doing this with behaviours. It was only the script I was lacking.
Thank you for the script, it definitely helped me to get this working. I had 2 issues with it. First was a syntax error regarding the variable $fieldAValue in the def iql. It had to be between double quotes.
Second issue I encoutered was that the variable for showFieldB was always false, even when the field value in field A changed and the searchResults.size was larger than 0. I modified it with an if /else statement and now it works
{code}
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def fieldA = getFieldByName('Dienst')
def fieldB = getFieldByName('Organisatie team')
def fieldAValue = fieldA.value
log.warn("waarde van fieldA = $fieldAValue")
def iql = """objectType = "Team" and Dienst = "$fieldAValue" """
def searchResults = Assets.search(iql)
int searchResultsSize = searchResults.size()
boolean showFieldB = false
if(searchResultsSize > 0){showFieldB = true}
else {showFieldB = false}
fieldB.setHidden(!showFieldB)
{code}
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.