Hello,
I have a field called Resource Type for Application multiple select list. There are RAM, CPU and Pod Number options in this area. I also have 3 numeric fields named Memory Size, Number of Processors and Pod Count.
My question is;
If I choose the RAM option from my multiple select list field named Resource Type for Application, I want the Memory Size field, if I choose CPU, Number of processors, and if I choose pod, I want the pod count field to appear. Since my Resource type for application field is multiselect, I did not know how to write a behavior.
Can anyone help?
So, you have 3 fields that should be visible or not based on a specific value in a multi-select list being selected or not.
Here is how I would write this:
def multiSelectFieldName = 'Resource Type for Application'
def multiSelectField = getFieldByName(multiSelectFieldName)
def selectedValues = multiSelectField.value as List
def valueFieldMap = [
RAM : 'Memory Size',
CPU : 'Number of Processors',
'POD Number': 'Pod Count'
]
valueFieldMap.each { value, fieldName ->
def showField = selectedValues.contains(value)
getFieldByName(fieldName).setHidden(!showField)
}
Hi Peter,
You always help me. I solved the problem on your page. Thank you very much again.
Have a nice day :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@PD Sheehan -- This is wonderful, very elegant code.. Can this be applied to Jira service desk Portal too?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, behaviors work pretty much just the same in jira as in service desk portal.
I have found some slight differences when dealing with getting values from Insight custom fields. There are some inconsistencies as to whether you get a string or a size-1 array when a single value is selected. One is a string, the other is an array, I don't remember which is which off the top of my head.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will need to create a Server-Side Behaviour of the Multi-Select List for your requirement.
For the Behaviour code, you can try something like this:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def hardwareSelector = getFieldById(fieldChanged)
def hardwareSelectorValue = hardwareSelector.value.toString()
def memorySize = getFieldByName('Memory Size')
def numberOfProcessors = getFieldByName('Number of Processors')
def podCount = getFieldByName('POD Count')
memorySize.hidden = true
numberOfProcessors.hidden = true
podCount.hidden = true
if (hardwareSelectorValue == '[RAM]') {
memorySize.hidden = false
} else if (hardwareSelectorValue == '[CPU]') {
numberOfProcessors.hidden = false
} else if (hardwareSelectorValue == '[POD Number]') {
podCount.hidden = false
} else if (hardwareSelectorValue == '[RAM, CPU]') {
memorySize.hidden = false
numberOfProcessors.hidden = false
} else if (hardwareSelectorValue == '[RAM, POD Number]') {
memorySize.hidden = false
podCount.hidden = false
} else if (hardwareSelectorValue == '[CPU, POD Number]') {
numberOfProcessors.hidden = false
podCount.hidden = false
} else if (hardwareSelectorValue == '[RAM, CPU, POD Number]') {
memorySize.hidden = false
numberOfProcessors.hidden = false
podCount.hidden = false
}
Please note that the sample working code provided is not 100% exact to your environment. Hence, you will need to modify the code accordingly.
Below is a print screen of the Behaviour configuration:-
Also, I am including a few test print screens:-
1. By default, when no option from the multi-select is picked, all the number fields are hidden, as shown in the image below:-
2. When any single option is selected, as shown in the images below, only a single field will be displayed, and the other fields will be hidden.
3. When multiple options are selected, multiple fields will be made visible, as shown in the images below:-
4. Finally, if you select all the options, all the fields will be visible as shown below:-
I hope this helps to solve your question. :)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Ram for your very detailed explanation. It helped a lot.
Have a nice day :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Didem Seda Taş Behaviour for Multi Select in avaiable on Adaptivist library , you can check this :-
https://library.adaptavist.com/entity/get-the-values-of-a-multi-select-field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikrant,
I couldn't find the script I was looking for. Thank you for your attention :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Didem Seda Taş You only to do minor change in the given script, it's very simple :-
You need to apply Behaviour on Multi select list field :-
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())
// Set log level
log.setLevel(Level.DEBUG)
def multiSelectField = getFieldByName('MultiSelectA')//multiselect list field name
def ram_size = getFieldByName("Memory Size")// do same for other two fields
// Value for a multi-select field will always be a list even if "None" is selected
def multiSelectFieldValue = multiSelectField.value as List
// If value is RAM
if (multiSelectFieldValue == [RAM]) {
ram_size.setHidden(false)
// If a given string is selected
} else if (multiSelectFieldValue == ["RAM" | "CPU"]) {
ram_size.setHidden(false)
cpu_size.setHidden(false)
// If more than 1 value is selected
} else if ( multiSelectFieldValue.size() > 2 ) {
ram_size.setHidden(false)
cpu_size.setHidden(false)
}
Try this it should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again, I made the code you wrote below, but it didn't work, what could be the problem?
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())
// Set log level
log.setLevel(Level.DEBUG)
def multiSelectField = getFieldByName('Resource type for application')//multiselect list field name
def ram_size = getFieldByName("İzin Tipi")// do same for other two fields
def CPU = getFieldByName("İzin Sebebi")// do same for other two fields
def Podsayısı = getFieldByName("HPA Metric")// do same for other two fields
// Value for a multi-select field will always be a list even if "None" is selected
def multiSelectFieldValue = multiSelectField.value as List
// If value is RAM
if (multiSelectFieldValue == ["RAM"]) {
ram_size.setHidden(false)
CPU.setHidden(true)
Podsayısı.setHidden(true)
}
// If value is CPU
if (multiSelectFieldValue == ["CPU"]) {
ram_size.setHidden(true)
CPU.setHidden(false)
Podsayısı.setHidden(true)
}
// If value is RAM
if (multiSelectFieldValue == ["Pod Sayısı"]) {
ram_size.setHidden(true)
CPU.setHidden(true)
Podsayısı.setHidden(false)
}
// If a given string is selected
else if (multiSelectFieldValue == ["RAM" && "CPU"]) {
ram_size.setHidden(false)
CPU.setHidden(false)
Podsayısı.setHidden(true)
}
// If a given string is selected
else if (multiSelectFieldValue == ["RAM" && "Pod Sayısı"]) {
ram_size.setHidden(false)
CPU.setHidden(true)
Podsayısı.setHidden(false)
}
// If a given string is selected
else if (multiSelectFieldValue == ["Pod Sayısı" && "CPU"]) {
ram_size.setHidden(true)
CPU.setHidden(false)
Podsayısı.setHidden(false)
}
// If more than 1 value is selected
else if ( multiSelectFieldValue.size() > 2 ) {
ram_size.setHidden(false)
CPU.setHidden(false)
Podsayısı.setHidden(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Didem Seda Taş :- Following script is working when one value is selected in multi select list field or all three selected but not working when selecting two value :(
@Ram Kumar Aravindakshan _Adaptavist_ @PD Sheehan Can you please help us in making the following script 100% working.
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())
// Set log level
log.setLevel(Level.DEBUG)
def multiSelectField = getFieldById(fieldChanged)//multiselect list field name
def ram_size = getFieldByName("RAM")// do same for other two fields
def CPU = getFieldByName("CPU")// do same for other two fields
def Podcount = getFieldByName("Pod Count")// do same for other two fields
// Value for a multi-select field will always be a list even if "None" is selected
def multiSelectFieldValue = multiSelectField.value as List
// If value is None
if (multiSelectFieldValue == [null]) {
ram_size.setHidden(true)
CPU.setHidden(true)
Podcount.setHidden(true)
}
// If value is RAM
if (multiSelectFieldValue == ["RAM"]) {
ram_size.setHidden(false)
CPU.setHidden(true)
Podcount.setHidden(true)
}
// If value is CPU
if (multiSelectFieldValue == ["CPU"]) {
ram_size.setHidden(true)
CPU.setHidden(false)
Podcount.setHidden(true)
}
// If value is POD NUMBER
else if (multiSelectFieldValue == ["POD NUMBER"] ) {
ram_size.setHidden(true)
CPU.setHidden(true)
Podcount.setHidden(false)
}
// If a given string is selected
else if (multiSelectFieldValue == ["RAM" && "CPU"]) {
ram_size.setHidden(false)
CPU.setHidden(false)
Podcount.setHidden(true)
}
// If a given string is selected
else if (multiSelectFieldValue == ["POD NUMBER" && "CPU"]) {
ram_size.setHidden(true)
CPU.setHidden(false)
Podcount.setHidden(false)
}
// If more than 1 value is selected
else if ( multiSelectFieldValue.size() > 2 ) {
ram_size.setHidden(false)
CPU.setHidden(false)
Podcount.setHidden(false)
}
Thanks
V.Y
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems what you want can be provided by the Cascading select field. There are two levels for this field where the options in level 2 are conditioned by the choice made in level 1. Can you give that a try?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jack, thank you very much for your interest :)
I'm not good at behavior. I don't know how to edit the way you mentioned :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I may have misread your original post. My suggestion was not associated with Behaviors at all. Rather I was suggesting the use of a cascading select field type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.