Forums

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

Cannot get script runner Field behavior script to work

Nannette Mori
Contributor
July 26, 2022

Jira Data Center Version 8.20.1

Script runner 6.46.0

I am using the behavior option in script runner to require/show a text field based on a value in a list field.  Using debug logging it works but never gets into the if statement.   I set the behavior on Affected Artifacts field as that is the list I am getting the value.  

 

Below is my code

def.af = getFieldByName("Affected Artifacts")

def afo = getFieldByName("Afftected Artifacts (Other) ")

afo.setHidden(true)

if (afVal == "Other) {

 afo.setHidden(False)

 afo.setRequired(true)

{

2 answers

0 votes
Vikrant Yadav
Community Champion
July 26, 2022

Hi @Nannette Mori  

Apply Behaviour on AF field and add below script, You are missing getValue in your script :- 

def af = getFieldByName("AF")
def afo= getFieldByName("AFO")

log.debug("dropdown value" + af.getValue())
if (af.getValue() == "Other") {
afo.setHidden(true)
}else {
afo.setHidden(false)
}

 Thanks

Vikrant Yadav
Community Champion
July 26, 2022

@Nannette Mori  Kindly share the complete script which you applied on af (select list field) behaviour. Might be some mistake in script. 

0 votes
Nic Brough -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.
July 26, 2022

I don't think it can execute the if statement.

You start it with "if (afVal ==", but your script does not define afVal, so the script has to evaluate the if as false.

I think you need to add a line like

def afVal = af.value

or change line 1 to 

def afVal = getFieldByName("Affected Artifacts").value

Nannette Mori
Contributor
July 26, 2022

I apologize

 

I inadvertently left this out of my script example, I had this line before the If statement

def afVal = af.getValue().toString 

Nannette Mori
Contributor
July 26, 2022

So I did define afval and it still doesn't work

Nic Brough -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.
July 27, 2022

Can you give us the whole script?

Suggest an answer

Log in or Sign up to answer