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

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

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"))

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?

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)?

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!

try like this if the custom field type is text

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

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

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!

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())

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 10 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

34 views 0 3
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