Show text field based on selection in list

C Streic August 15, 2017

Dear All,

 

I am a first time user of Jira Software and am currently trying to set up an issue with several fields, with some only being shown based on the value a user previously selects. 

To implement this, I am using the ScriptRunner add-on. When trying to add a behaviour to a text field to make it appear only if a user selects a certain value from a list, i.e. a custom field, nothing happens. 

Here is my code:

def reqValF= getFieldById('customfield_10501')
def depTxtF = getFieldById('customfield_10503')


def reqValF_val = reqValF.getValue()


if (reqValF_val == "New"){
depTxtF.setHidden(false)
}else{
depTxtF.setHidden(true)
}

 

Thank you! 

2 answers

1 vote
Jenna Davis
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.
August 15, 2017

Hello, 

I think you were pretty close. You need to specify 'as String' in order to compard the value of the field to a string. 

def reqValF= getFieldById(getFieldChanged())
def depTxtF = getFieldById('customfield_10503')


def reqValF_val = reqValF.getValue() as String


if (reqValF_val != "New"){
depTxtF.setHidden(true)
}else{
depTxtF.setHidden(false)
}

 I have not tested this directly, but it should work. Let me know if you have any problems. :)

Regards, 

Jenna

C Streic August 16, 2017

Hello Jenna,

 

thank you for your reply! Unfortunately it doesn't work. Is it ok to add the script to the 'edit server side script'-section of my custom field or do I need to import something? I have not set up a dev environment as I am currently on a tight schedule.

 

Thanks

Joshua Yamdogo @ Adaptavist
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.
August 16, 2017

Hi Christina,

Yes, putting the script in the server side script seciton is fine. I have tested Jenna's code and it does work. However, I think you may just have the behaviour on the wrong field. The behaviour should be on the Select List (reqValF). The behaviour should not be on the text field that you want to hide.

C Streic August 17, 2017

Hi Joshua, unfortunately I could not figure out where the problem lies. I switched to JJupin now. Here it works.

 

Thanks again!

0 votes
Hemanth Kumar September 27, 2022

It worked for me ..

 

for DSCGLOB project - if "ATO" field is 'Yes' then show text field "ATO Location"

def reqValF= getFieldById('customfield_56138')    //Field to check for input - New
def depTxtF = getFieldById('customfield_56432')  //Display this field if its New

def reqValF_val = reqValF.getValue()

if (reqValF_val == "Yes"){
depTxtF.setHidden(false)
}else{
depTxtF.setHidden(true)
}

Suggest an answer

Log in or Sign up to answer