Calculate lifetime of a product

Arthur S December 17, 2021

Hi,

 

I would like to calculate the lifetime of a product based on the difference between when the product has been released (custom field Launch date) and now.

I was trying to do it with the duration scripted field in scriptrunner but I have an issue : 

((System.currentTimeMillis() - customField[14311].getTime())/1000).toLong() 

 

Here is the error message :

 groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.getAt() is applicable for argument types: (Integer) values: [14311] Possible solutions: getAt(java.lang.String), getId(), getName(), putAt(java.lang.String, java.lang.Object), wait(), grep() at Script101.run(Script101.groovy:1)

 

 

Can anyone help ?

Thank you 

2 answers

1 accepted

0 votes
Answer accepted
Arthur S December 17, 2021

I figured it out, here is the final code :

((System.currentTimeMillis() - getCustomFieldValue('Launch Date').getTime())/1000).toLong()

Thanks for your time Ravi :)

 

Arthur 

0 votes
Ravi Sagar _Sparxsys_
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.
December 17, 2021

Hi @Arthur S 

There are few ways of doing it.

The snippet below has a method which I use a lot for date calculation.

def duration = TimeCategory.minus(
new Date(),
issue.created
)

However the script on the page match closely to your requirements.

Ravi 

Arthur S December 17, 2021

Hi @Ravi Sagar _Sparxsys_ ,

 

What I am trying to do is to create a custom scripted field on "Duration" template.

When I do it this way :

((System.currentTimeMillis() - issue.created.getTime())/1000).toLong()

I have the following result :

48 weeks, 13 hours, 36 minutes 

 

But instead of comparing it to the created date, I would like to compare it to my custom field "Launch Date". 

For my understanding, this is giving me the field value : 

customField[14311]

but I am not sure how to convert it to the right type to compare it to System.currentTimeMillis()

 

Thanks,

Arthur

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.2
TAGS
AUG Leaders

Atlassian Community Events