Remove decimal points when adding Number Field to summary

I have some numbers saved in an issue in number fields. I want on a transition to create a new issue and add some of these numbers to the summary. I'm adding this: 

issue.summary = 'Clean Range Take Version ' + cfValues['Take Version 1'] + ': ' + cfValues['Clean Range 1 Start'] + ' - ' + cfValues['Clean Range 1 Stop'] + ' ' + sourceIssue.summary

 

This is working fine except for the fact that the summary has a useless decimal point for some reason. Any idea how can I remove these?

chrome_2016-12-07_12-01-40.png

1 answer

1 accepted

That's probably because the numbers are getting stored as floating point numbers OR as version objects (which are getting coerced to strings like 10.0). You could convert them with normal Groovy/Java casting.

//If the custom field is a string value and is actually 10.0, the below should be safe
(cfValues['Take Version 1'] as Double) as Integer
//If it's actually stored as a number, you could probably leave out the case to Double
cfValues['Take Version 1'] as Integer
//Or, roughly equivalently, and a bit more null safe
cfValues['Take Version 1']?.toInteger()

Another alternative would be to add a line to strip out the trailing numbers:

issue.summary = issue.summary.replaceAll("\\.0")

Thanks a lot for the detailed answer. As it's a number field, just adding "as Integer" after solved it.

I don't have to worry about null values as that is part of the condition for the postfunction - it doesn't trigger if these fields are empty.

issue.summary = 'Clean Range Take Version ' + (cfValues['Take Version 1'] as Integer) + ': ' + (cfValues['Clean Range 1 Start'] as Integer) + ' - ' + (cfValues['Clean Range 1 Stop'] as Integer) + ' ' + sourceIssue.summary

chrome_2016-12-07_13-35-28.png

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,313 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot