Hi,
Hoping I'm missing something simple with this. I've got a scripted field which calculates the Age of a JIRA ticket in days based on the current time and created timestamp and I'd like to display this as a rounded integer, but the indexer insists on a Double being returned and displaying decimal places. The code is really simple:
def createTime = issue?.getCreated()?.getTime(); Date now = new Date() def currentTime = now.getTime() def createdAgo = (currentTime - createTime) / 86400000 // milliseconds in a day if (createdAgo) { return createdAgo.toDouble().round(0) } else { return 0 }
but this returns values such as 6.0, 11.0, 9.0, 56.0, etc. when I just want 6, 11, 9, 56, etc.
If I change the return statement to
return createdAgo.toDouble().round()
then it displays what I want, but I get the following error:
"The indexer for this field expects a java.lang.Double but the script returned a java.lang.Long - this will cause problems."
I've tried every combination of trunc(), round(),floor(), etc. that I can think of, but I always end up in the same place. I either return a Double, which displays decimal places, or I end up with a Long or Integer which doesn't display decimal places, but gives the above error and causes issues to fail to re-index when they're edited.
It needs to be a Number field rather than a String so people can search for Age > 10, Age <= 7, etc.
Am I missing something obvious?
Cheers.
Community moderators have prevented the ability to post new answers.
You have possibility of creating custom template using velocity numberTool variable. Something like
$numberTool.format('integer',$value)
Anyway, your expectation that Age would be automagically incremented is false. Scripted fields are calculated and stored into index only if issue is updated (or explicitly reindexed).
Hint: It's better to teach your users to use created < -10d
or created <= -7d
.
Thanks Jozef. But an issue is indexed when it's created so it always has an indexed created date? Are you saying: Date now = new Date() def currentTime = now.getTime() only returns the date that the issue was last re-indexed?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ignore that comment, I understand what you mean.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As Jozef says, script fields cannot be used for calculating a value where one of the inputs is "outside" the issue, eg current time. They will refresh when the issue is viewed, and the value is stored in the index only when the issue is updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.