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
Hi Joseph Chung Yin, Tansu Akdeniz,
I put my script on side-server (my "CustomX" fields really name "Typ Stacji")
and set mapping on specific project.
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
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you check "Use Service Desk mapping"? Otherwise it works in internal Jira UI.
Also you can use field.setHelpText() step by step within the code to print & check values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joseph Chung Yin, Tansu Akdeniz,
I put my script on side-server (my "CustomX" fields really name "Typ Stacji")
and set mapping on specific project.
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
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.