How to use behaviours on issue creation screen

Cedric_DEVAUX June 5, 2017

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)
}

 Image 1.png

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

2 answers

0 votes
Cedric_DEVAUX June 7, 2017

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).

 

Picture 1.png

Picture2.png

I think the new value of "Equipment Type 1" is not taking into account on the current field.

 

 

adammarkham
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.
June 7, 2017

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.

Cedric_DEVAUX June 12, 2017

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

https://community.atlassian.com/t5/JIRA-questions/How-to-add-a-Behaviour-on-a-transition-Screen-for-a-particular/qaq-p/398960

and I want if it's the only solution or if it's have another solution?

 

Thank you.

Cedric_DEVAUX June 12, 2017

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

0 votes
adammarkham
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.
June 6, 2017

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. 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events