Problem with converting a string to integer for a Calculated Number Field

Yunzhu GE August 13, 2013

Hi,

I'm trying to convert a custom field of type "text field" into integer with the following approch:

<!-- @@Formula:

Integer.parseInt(issue.get("customfield_10328"))

-->

Then I got the following error message:

I'm using Jira V4.3.3 and jira-misc-custom-fields-1.1.2. I'm new in Jira and Javascript, so sorry if the question seems to be stupid... ;)

Thanks & regards,

Yunzhu

6 answers

1 accepted

1 vote
Answer accepted
David _old account_
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 Leaders.
August 13, 2013

This is probably because your customfield_10328 can sometimes have a null value. So you should test against null values before converting to int:

issue.get("customfield_10328")==null ? 0 : Integer.parseInt(issue.get("customfield_10328"))

Yunzhu GE August 13, 2013

Thanks for your answer, i've already tried this but it dosen't work, so i used the simplest instruction to test. When i try the above code, i got this:

So is it means that i got a problem with my library or somthing like that?

1 vote
Yunzhu GE August 18, 2013

Nothing else on the screen except for "Method Invocation Integer.parseInt".

Finally I will abandon this idea, in fact we are not allowed to install any plugin in our Jira system... Thank you anyway for your help!

0 votes
Phillip Ponzer [Cprime]
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 Leaders.
August 18, 2013

Just to answer the question then, what this is saying is that there exists no function called "parseInt" that accepts a double as its only parameter.

A few ways to get around this is to cast the Double to an Integer:

(Integer)(issue.get("customfield_10328"))

Or run toString() on the Double (make sure it's not null!) and then pass that to Integer.parseInt:

Integer.parseInt(issue.get("customfield_10328").toString())

0 votes
Phillip Ponzer [Cprime]
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 Leaders.
August 13, 2013

Is there anything else following "Method Invocation..." left out of the screenshot?

0 votes
RambanamP
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 Leaders.
August 13, 2013

try like this if the custom field type is text

Integer.parseInt((String)issue.get("customfield_10328"))

0 votes
David _old account_
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 Leaders.
August 13, 2013
Are you sure your custom field is of type text and always contains a valid integer string? Also, can you look in Atlassian-jira.log for a more descriptive error (with stack trace)?
Yunzhu GE August 18, 2013

I tried with a custom field of type integer and instead of "Method Invocation" I got the following error:

Finally I will abandon this idea, in fact we are not allowed to install any plugin in our Jira system... Thank you anyway for your help!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events