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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Show specific values based on previous custom field Edited

I'm looking for a way to display only certain values of a customfield based on the value of a previous customfield. I do not want to hide/show the entire customfield, only limit the values available. Is there a way to achieve this?

 

import com.atlassian.jira.component.ComponentAccessor

def optionsManager = ComponentAccessor.getOptionsManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

def lobField = getFieldById("LOB:")
def lobProgram = getFieldById("LOB:Programs")
def lobProject = getFieldById("LOB:Project")

def cfLobField = cfManager.getCustomFieldObjectByName("LOB:Programs")
def fcLobField = cfLobField.getRelevantConfig(issueContext)
def lobOptions = optionsManager.getOptions(fcLobField)

def analyzeSet = ["MGV", "BLAST"]


if(lobField.getValue() == "Analyze"){
lobProgram.setFieldOptions(lobOptions.findAll{it.value in analyzeSet}.collectEntries { [(it.optionId).toString() in it.value] })
}

1 answer

1 accepted

1 vote
Answer accepted

Hi dude 

Ill try out in my instance and share you the code .

Hi @Raynard Rhodes 

I have created a behaviour and two custom fields - data base type and data base version 

and in the behaviour select the first field based on which the second custom field value should be filtered.This code works out for me try this in your instance and later modify it accordingly.

Cheers ...!

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def optionsManager = ComponentAccessor.getOptionsManager()


def picklist8 = getFieldByName("Database Type")

def picklist9 = getFieldByName("Database Versions")

def customField =
customFieldManager.getCustomFieldObject(picklist8.getFieldId()) // Pick list Field that dictates other fields on form based on its value

def config = customField.getRelevantConfig(getIssueContext())

def options = optionsManager.getOptions(config)




def customField1 =
customFieldManager.getCustomFieldObject(picklist9.getFieldId()) // Pick list Field that dictates other fields on form based on its value

def config1 = customField1.getRelevantConfig(getIssueContext())

def options1 = optionsManager.getOptions(config1)




if (picklist8.getValue() as String == "My SQL") {




def optionsMap8 = options1.findAll

{it.value in ["MySQL 5.5","MySQL 5.7"] // list of options you want to show on Biz Priority Field

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

picklist9.setFieldOptions(optionsMap8)

}




else if (picklist8.getValue() as String == "MS SQL"){




def optionsMap8 = options1.findAll{

it.value in ["MSSQL 2014","MSSQL 2016"] // list of options you want to show on Biz Priority Field

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

picklist9.setFieldOptions(optionsMap8)


}

else if (picklist8.getValue() as String == "SQL Lite") {

def optionsMap8 = options1.findAll

{

it.value in ["SQL Lite 2.1","SQL Lite 3.0"] // list of options you want to show on Biz Priority Field

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

picklist9.setFieldOptions(optionsMap8)

}
Like Raynard Rhodes likes this

@Kevin Johnson I appreciate your assistance. A bit later that day I did get my code working. I'll post my results Monday. I'll also give your code a try and may be effectively code mine. 

Like Kevin Johnson likes this

Below is the code I used.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FormField

@BaseScript FieldBehaviours fieldBehaviours

Issue issue = underlyingIssue as Issue
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

FormField lob = getFieldByName("LOB: ")
FormField lobPrograms = getFieldByName("LOB:Programs ")
FormField lobProject = getFieldByName("LOB:Project ")


def lobPrograms2 = customFieldManager.getCustomFieldObjectByName("LOB:Programs ")
def lobProject2 = customFieldManager.getCustomFieldObjectByName("LOB:Project ")

def lobProgramsValue = lobPrograms.getValue()
def lobValue = lob.getValue()

def fieldConfig = lobPrograms2.getRelevantConfig(issue)
def fieldConfig2 = lobProject2.getRelevantConfig(getIssueContext())

def allowedOptions = null

def getOptions = optionsManager.getOptions(fieldConfig)
def getOptions2 = optionsManager.getOptions(fieldConfig2)

if(lobValue=="Option1 || lobValue=="Option2){
lobPrograms.setFieldOptions(getOptions.findAll{
it.value in ["This is to be shown", "This one, too!"]
})}

if(lobValue=="Option1" && lobProgramsValue=="This is to be shown"){
lobProject.setFieldOptions(getOptions.findAll{
it.value in ["This is the third option"]
})}

The first if statement is to change field 2 based on field 1. The second if statement is to change field 3 based on field 1 and 2. I just keep repeating the if statement for each unique change. 

Like Kevin Johnson likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,624 views 22 33
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you