The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

2 field values multiply

kak17
April 8, 2017

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
}
erro.png

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
Nic Brough -Adaptavist-
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 Champions.
April 8, 2017

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)

kak17
April 8, 2017

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

Nic Brough -Adaptavist-
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 Champions.
April 9, 2017

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)

TAGS
AUG Leaders

Atlassian Community Events