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 widget could not be displayed.

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?

This widget could not be displayed.
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!

This widget could not be displayed.

try like this if the custom field type is text

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

This widget could not be displayed.

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

This widget could not be displayed.

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!

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

523 views 3 19
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