2 field values multiply Edited

1.uesing script runner

2.create a Script Fields:"cost"

3.Custom 2 fields:number(num type),price(num)

how i can get the cost value using groovy script, once we have updated the filed values pirce, number then immediately calculate the field value cost.

this is my scprit:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def price = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("price"))
def num = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("num")
if (price) {
return price * num)
else {
return null


1 answer

2 votes

The field values you are pulling back are objects, not simple numbers.  You need to convert the contents to numbers before you can multiply them together (and bear in mind they might be nulls too, which you'll want to capture and handle)

but price and numbers fields is number type, still need convert???

Look at the error message you showed in your original before you changed the question - the error was saying that the calls to get the field data had returned an object, not a number.

So yes, you need to convert the objects returned into numbers.  (Trying to multiply objects tends not work - yes the  objects you get from the fields might be "4" and "5", but they might also be "banana" and "apple", and there's no way to know what you might want from multiplying those together)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

936 views 3 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you