Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
I try to use Behaviours on creation screen in order to show and become required some customfields depending of the value of another customfield.
For the moment, I try with 1 customfield depending of another customfield value but at the end I would like to show and become required customfields depending to the value of another customfield
The objective is to show/required the customfield called "VM Type" when the value of the customfield called "Equipment Type" is equal to "Virtual Server".
Below my serverside script, I don't have any error but It does'nt work.
import com.onresolve.jira.groovy.user.FormField
// *********** Customfields ***********
// customfield_16393 = Equipment Type => JIRA Insight customfield
// customfield_16420 = VM Type => Select List
// ************************************
FormField EquipmentType = getFieldById("customfield_16393")
FormField VmType = getFieldById("customfield_16420")
if (EquipmentType.getFormValue() == "Virtual Server") { //Yes
VmType.setHidden(false)
VmType.setRequired(true)
}
else {
VmType.setHidden(true)
VmType.setRequired(false)
}
For your information the customfield "Equipment Type" is a JIRA Insight customfield (Asset Management Addon).
In addition I add a screenshot of the settings of behaviour.
It's my 1st time to use behaviours and I need help.
Thank you in advance for your help.
Cedric
Hello Adam,
It works with a select list ... but partially :) ...
I replace Insight customfield to select list, I check the value ID of my select list "Equipment Type 1" to show/require the field "VM Type"
import com.onresolve.jira.groovy.user.FormField
// *********** Customfields ***********
// customfield_16437 = Equipment Type 1 => Select List
// customfield_16420 = VM Type => Select List
// ************************************
FormField EquipmentType = getFieldById("customfield_16437")
FormField VmType = getFieldById("customfield_16420")
// ID "18457" correspond of the value "Virtual Server"
if (EquipmentType.getFormValue() == "18457") { //Yes
VmType.setHidden(false)
VmType.setRequired(true)
}
else {
VmType.setHidden(true)
VmType.setRequired(false)
}
In order to check if the script works, I set up the default value of "Equipment Type 1" to "Virtual Server" in order to show/require the customfield "VM Type".
The customfield "VM Type" appears and it's required (1st picture) but ... If I change the value of "Equipment Type1" normally the customfield "VM Type" should disappear and become optional but it's not working (2nd picture).
I think the new value of "Equipment Type 1" is not taking into account on the current field.
I think I see what is wrong. If you want the validation script to trigger everytime Equipment Type 1 is changed then you should attach it to that field instead rather then the VM Type field.
Let us know if that resolves your problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes it works :)
I have another question around this topic, now I want to use the same function on transition screen.
I find this post
and I want if it's the only solution or if it's have another solution?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this:
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.fields.screen.*
import com.atlassian.jira.component.ComponentAccessor
// *********** CF Definitions ***********
FormField Nature = getFieldById("customfield_16438")// customfield_16438 = Nature of the request
FormField NatureR = getFieldById("customfield_16444")// customfield_16438 = Nature of the request reason
FormField EquipmentType = getFieldById("customfield_16437")// customfield_16437 = Equipment Type
FormField VmType = getFieldById("customfield_16420")// VM Type
FormField BackupT = getFieldById("customfield_16415")// Backup Type
FormField Port = getFieldById("customfield_16413")// Port
def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def currentscreen = getFieldScreen().id
if (currentscreen == "16507"){
// Case: Transition screen ID = 16507 => "IT-CHG MGT New Equipment Creation transition"
if (EquipmentType.getFormValue() == "18457") {
// Case Equipment Type ="18457" = "Virtual Server"
// Visible CF
VmType.setHidden(false)
HyperVS.setHidden(false)
...
I tried the method of Jamie described in the post but it's very strange it doesn't work too.
Do I 2 behaviours 1 for issue creation and second one for workflow transition or I do a mistake somewhere?
Cedric
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your script looks about right. Can you try it on a normal JIRA custom field type? Just to verify it works.
It's possible that behaviours won't work correctly with the custom fields types that are not provided by JIRA.
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.