Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get all possible values of an assets/insight based custom field

Mathias Eeckhout
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 19, 2023

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 ?

 

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 19, 2023

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)
Mathias Eeckhout
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 20, 2023

Hi @PD Sheehan 

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}

Suggest an answer

Log in or Sign up to answer