Forums

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

String comparison not working as expected

Neale Foulds
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 23, 2022

I am trying to use a custom script in scriptrunner to evaluate a transition condition.

The key differentiator for this transition is the value of a custom field single select list - the list has two possible values (NOC or IT)

My code is below;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.component.ComponentAccessor;

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager.getCustomFieldObject("customfield_11400")

def cFieldValue = issue.getCustomFieldValue(cField).toString()

log.warn("Field Value = "+cFieldValue)

if (cFieldValue != "IT") {

    return true

} else {

    return false
}

The log output is below;

2022-03-16 11:55:23,184+0000 [**ID removed] WARN [**Username removed] 715x519183x1 1vsq4ae [**IPs removed] /browse/CAB-472 [c.o.scriptrunner.runner.ScriptBindingsManager] Field Value = IT
2022-03-16 11:55:25,720+0000 [**ID removed] WARN [**Username removed] 715x519198x1 1vsq4ae [**IPs removed] /browse/CAB-517 [c.o.scriptrunner.runner.ScriptBindingsManager] Field Value = NOC

In two different browser windows, I have two issues open - one of each type that I am concerned with. The transition button should appear for one, but not the other. The button appears for both at all times.

For some reason, the string comparison in the IF statement for the above script does not work, and the transition always returns true (and therefore shows a button that I do not want all my users to see!)

I have tried different variations for string comparison in the IF statement,, such as;

"IT".equals(cFieldValue)

or

cFieldValue == "IT"

etc. 

Server info grab as follows;

Jira Info

Version8.13.9
Build Number813009
Build DateThu Jul 15 00:00:00 UTC 2021
Build Revision6b24593e988639831c5b135a30425606cfbabcba
Installation TypeStandalone

My Script Runner installation details as follows;

Version: 6.36.0
Support: Supported by vendor
App key: com.onresolve.jira.groovy.groovyrunner

Any help is appreciated... 

1 answer

0 votes
Aron Gombas
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.
March 23, 2022

I'd check whether after this line:

def cFieldValue = issue.getCustomFieldValue(cField).toString()

...the type of "cFieldValue" is actually a string? 

(I know it should be, but we have seen many weird things in Groovy-land.)

Suggest an answer

Log in or Sign up to answer