Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

customfields.option.lazyloadedoption to class int

Hey I'm using scriptRunner,

I'm trying to set a textfield value based on calculation of two selected values from two different list. (post function)

For example: list1[1, 2, 3] list 2[4,5,6] textfield val= list1val*list2val

The main issue is i can't convert the selected values into integer in order to do the calculation (i'm converting it to int using as int) and  in the post function area the error says: customfields.option.lazyloadedoption to class int.

Thanks in advance

2 answers

0 votes

You can't just cast an object to another type if the objects are totally different. 

An option is not a number and has nothing in common with a number.

You will need to code rules that read the option and set a number, or if your select list really will only have numbers as their option names, then you could use the parseint function to convert. 

As Nic says - Option is a totally different class from Integer.


If your values are always numerical then you would first need to get the value itself, and convert that, not the whole Option.


So if you do

def cfValue = issue.getCustomFieldValue(selectField)

This should return a LazyLoadedOption to my best-shabby-and-totally-unreliable-memory.

From this LazyLoadedOption, you now need to get the actual String value (the option name) - (first bookmarked javadoc, it will be the same with Cloud anyway though), so

String optionName = cfValue.getValue()


Then, assuming this is a valid number, you can cast it to an Integer:


or the Groovy way

def optionName = cfValue.getValue()
int optionName = cfValue.getValue() as int


If you're using dynamic classes like 'def' then Groovy should be able to do Math operations on those values if they are numerical, because Groovy just identifies if they are compatible types.

The main difference is not to do this operation with the LazyLoadedOption, you need to get the "value" first.


With Cloud though I do not know if you are handling this through Java API directly or if you need to fetch json with REST -- I don't automate Cloud so I don't know the options there too well, my suggestion above would apply to Server.

However, this should hopefully get you in the right way regardless of using Java or REST.

Suggest an answer

Log in or Sign up to answer
Site Admin

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you