Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

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

Edited

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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 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)

Hi @Peter-Dave 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