Forums

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

Compare integer value from select list using scriptrunner

Vishal
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.
February 28, 2023

Hi Team,

I have a simple groovy script to get the selection values & based on that perform certain actions in scriptrunner behaviour.

import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.optionsManager

def Options = getFieldById(getFieldChanged()) as FormField
def Selection = Options.getValue()
if(Selection == "This"){
     // Do this
}
if(Selection == "That"){
     // Do that
}
This works completely fine when the select list options are text options, but it does not work for numbers, for example if they select option 502 I would like to take action acccordingly, can someone help, what am I missing in here ? Below doesnt work.
if(Selection == "502"){
     // Execute this
}
Thanks in advance.

2 answers

1 accepted

0 votes
Answer accepted
Vishal
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 2, 2023

If anyone looking for the answer, the integer values work as well withough any change, my bad I was looking at wrong place, the problem was with the action part & not with selection returning wrong value. Below is perfectly fine way to capture even integers.

if(Selection == "502"){
     // Execute this
}
0 votes
Tuncay Senturk _Snapbytes_
Community Champion
March 1, 2023

Hi @Vishal 

I am not sure but could you please try any of the below?

integer compare:

if (Selection == 502)

string compare:

if (Selection.toString() == "502") { 
Vishal
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 2, 2023

Hi @Tuncay Senturk _Snapbytes_ 

thanks for your reply but the problem was with the action & not with the camparing.

Suggest an answer

Log in or Sign up to answer