Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Show / Hide Custom fields depends on other custom fild value

Bartosz Krol September 27, 2021

Hello,

I want to implement a solution where 3 different custom fields will be automaticly show / hide depends on value in other custom field.

 

At this moment I have four diffrent cf:

- CustomX - select list (single choise). I have an options: Test1, Test2, Test3, Test4, Test5, Test6

- CustomA - Checkbox

- CustomB - Checkbox

- CustomC - Checkbox

 

I created Behaviours (Scriptrunner) but don't work properly. My Beahaviors:

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor

def CustomXField = getFieldByName("CustomX")
def CustomAField = getFieldByName("CustomA")
def CustomBField = getFieldByName("CustomB")
def CustomCField = getFieldByName("CustomC")

def wybranytyp = CustomXField.getValue()
log.warn "typ :" + wybranytyp

if (wybranytyp == "Test1") {
CustomAField.setHidden(false)
CustomBField.setHidden(true)
CustomCField.setHidden(true)
if (wybranytyp == "Test2") {
CustomAField.setHidden(false)
CustomCField.setHidden(true)
CustomBField.setHidden(true)
if (wybranytyp == "Test3") {
CustomAField.setHidden(false)
CustomCField.setHidden(true)
CustomBField.setHidden(true)
if (wybranytyp == "Test4") {
CustomCField.setHidden(false)
CustomAField.setHidden(true)
CustomBField.setHidden(true)
if (wybranytyp == "Test5") {
CustomCField.setHidden(false)
CustomAField.setHidden(true)
CustomBField.setHidden(true)
if (wybranytyp == "Test6") {
CustomBField.setHidden(false)
CustomAField.setHidden(true)
CustomCField.setHidden(true)
}
else {
CustomAField.setHidden(false)
CustomBField.setHidden(false)
CustomCField.setHidden(false)

 

I don't know what I made wrong.

Best regards,

Bartosz

 

3 answers

0 votes
Bartosz Krol September 29, 2021

Hi Joseph Chung Yin, Tansu Akdeniz,

 

I put my script on side-server (my "CustomX" fields really name "Typ Stacji")script.PNG

 

and set mapping on specific project.

mapping.PNG

I don't know Joseph Chung Yin that my codes are incomplete? This is my first adventure with scriptrunner codes and I know that my knowledge is not too high.

Can you tell me what the loop should look like in my example correctly?

 

Regards,

Bartosz

0 votes
Joseph Chung Yin
Community Champion
September 27, 2021

@Bartosz Krol -

Where did you put the server-side script via behavior?  This should be placed as server-side script against the field = "CustomX".

In addition - your codes are incomplete.  Try the following for your if loop.  You will see that using if/else if should work properly.  

Hope this helps...

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.


... your other original codes

if (wybranytyp == "Test1") {
CustomAField.setHidden(false)
CustomBField.setHidden(true)
CustomCField.setHidden(true)
}
else if (wybranytyp == "Test2") {
CustomAField.setHidden(false)
CustomCField.setHidden(true)
CustomBField.setHidden(true)
}
else if (wybranytyp == "Test3") {
CustomAField.setHidden(false)
CustomCField.setHidden(true)
CustomBField.setHidden(true)
}
else if (wybranytyp == "Test4") {
CustomCField.setHidden(false)
CustomAField.setHidden(true)
CustomBField.setHidden(true)
}
else if (wybranytyp == "Test5") {
CustomCField.setHidden(false)
CustomAField.setHidden(true)
CustomBField.setHidden(true)
}
else if (wybranytyp == "Test6") {
CustomBField.setHidden(false)
CustomAField.setHidden(true)
CustomCField.setHidden(true)
}
else {
CustomAField.setHidden(false)
CustomBField.setHidden(false)
CustomCField.setHidden(false)
}

0 votes
Tansu Akdeniz
Community Champion
September 27, 2021

Hi @Bartosz Krol 

Did you check "Use Service Desk mapping"? Otherwise it works in internal Jira UI.

pic.png

 

Also you can use field.setHelpText() step by step within the code to print & check values.

Bartosz Krol September 29, 2021

Hi Joseph Chung Yin, Tansu Akdeniz,

 

I put my script on side-server (my "CustomX" fields really name "Typ Stacji")

 script.PNG

and set mapping on specific project.

 mapping.PNG

I don't know Joseph Chung Yin that my codes are incomplete? This is my first adventure with scriptrunner codes and I know that my knowledge is not too high.

Can you tell me what the loop should look like in my example correctly?

 

Regards Bartosz

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events