Forums

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

Calculate a scripted field using select fields

Shioban May 10, 2018

I have a scripted field that works as expected with number fields. How can I modify the inline script to work with a select list field? 

def cv1 = getCustomFieldValue(Field1) as Double;

def cv2 = getCustomFieldValue(Field2) as Double;

def cv3 = getCustomFieldValue(Field3) as Double;

return = (cv1 + cv2 + cv3)

Switching to a select list field, the value coming back is not a number. How do I convert it to a number so I can use it in a calculation?

 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
May 10, 2018

Hello,

If select list is not multiple select list, try below script 

Option option1 = (Option) getCustomFieldValue(Field1);
def cv1 = option1.getValue() as Double;
...
Shioban May 11, 2018

Tuncay,

The fields a re single select lists.

When I modify the inline script as you suggested, I get the following

 "unable to resolve class Option"

 

How do I resolve the class?

Shioban May 11, 2018

I have aded this to the scripted field:

import com.atlassian.jira.issue.customfields.option

But get the message 

   "unable to resolve class  com.atlassian.jira.issue.customfields.option"

Shioban May 11, 2018

I have added this to the inline script:

import com.atlassian.jira.issue.customfields.option;

and now get the message

"unable to resolve class  com.atlassian.jira.issue.customfields.option"

Tuncay Senturk _Snapbytes_
Community Champion
May 11, 2018

For sure, you have to import it.

import com.atlassian.jira.issue.customfields.option.Option;
Shioban May 11, 2018

Thank you!!!!

Tuncay Senturk _Snapbytes_
Community Champion
May 11, 2018

You're welcome ;)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events