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: 

Help with syntax for scripted field

Susan Hauth _Jira Queen_
Community Champion
May 21, 2014

I'm using Jamie's wonderful script runner but I'm not a coder and can't seem to get by the nulpointerexception.

So far I have this:

def urgency = getCustomFieldValue("Urgency")
def complexity = getCustomFieldValue("Complexity")
def need = getCustomFieldValue("Need")
def effort = getCustomFieldValue("Effort")
def result = (effort * complexity) / (urgency * need)
return result

Those 4 custom fields are all numeric and so is my script field (as well as the template and searcher are all set up as numeric).

I guess I need some sort of test to ensure that all of those numbers are not null before trying to do the calculation or else return null?

Can someone give me the code I need? Thanks...

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
JamieA
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.
May 22, 2014

Does the error only happen when one of them is zero? You also need to handle the case of them being zero, as well as null.

Try something like the following, if it doesn't work can you post the stack trace...

def urgency = getCustomFieldValue("Urgency") ?: 0
def complexity = getCustomFieldValue("Complexity") ?: 0
def need = getCustomFieldValue("Need") ?: 0
def effort = getCustomFieldValue("Effort") ?: 0
if (urgency > 0 && need > 0) {
    return (effort * complexity) / (urgency * need)
}
else {
    return 0 // or some very high number
}

Susan Hauth _Jira Queen_
Community Champion
May 22, 2014

Hi,

Well it didn't blow up so that's a positive step forward. But it calculated 0 where it should have calculated 2.25 for the test issue. effort = 3, complexity =3 , urgency =2, need =2

;-)

JamieA
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.
May 22, 2014

Hrmmm... are the names exactly as you have them above?

Susan Hauth _Jira Queen_
Community Champion
May 22, 2014

Ah...yes, one of the field names was not a duplicate of another type of field, so I have modified and it works like a charm! Thanks very, very much Jamie.

TAGS
AUG Leaders

Atlassian Community Events