How to use the Calculated text field

Hello!
I'm using JIRA Software 7.1.0
I'm trying to use formula but it doesn't works....

<!-- @@Formula:
if (issue.get("resolutiondate") == null)
return ((new Date()).getTime() - issue.get("created").getTime()) / 1000 / 3600 /24 + "days";
else
return (issue.get("resolutiondate").getTime() - issue.get("created").getTime()) / 1000 / 3600 /24 + "days";
-->

What should I do...Please help me...

2 answers

1 accepted

Accepted Answer
3 votes

Please describe the input and output in english: I could much more easily write a new formula than try to guess what your end-game is.

Thank you for your reply.

In the Servicedesk project I would like to calculate how many days it took to resolve since the ticket was issued.
I want to display "XX days".

1. If there is a resolution date (status is closed), "resolution date - creation date"
2. If there is no resolution date (status is not closed), "today - creation date"

How can I do it?

Okay, I think your script is actually just fine. The approach seemed fine and the syntax was correct. 

However, the script has this error when running:

CalculatedTextField: error evaluating formula of field "Age (Calculated)" of issue JIRA-833: 
    Sourced file: inline evaluation of: ``  if (issue.get("resolutiondate") == null)  return ?(new Date()).getTime() - iss . . . '' Token Parsing Error: Lexical error at line 3, column 8.  Encountered: "\uff08" (65288), after : "": <at unknown location>
    
    Navigate to the following URL to edit the formula: https://jira-sandbox.example.corp/secure/admin/EditCustomField!default.jspa?id=19800

Within your script, there is an invalid character. This appears to be one of your parenthesis: "(" vs "(".

Thus, updating your script to fix that character works just fine. I also added a space to the " days" string.

Source

<!-- @@Formula:
if (issue.get("resolutiondate") == null)
return ((new Date()).getTime() - issue.get("created").getTime()) / 1000 / 3600 /24 + " days";
else
return (issue.get("resolutiondate").getTime() - issue.get("created").getTime()) / 1000 / 3600 /24 + " days";
-->

Example

image.png

You may want to consider implementing this as a Calculated Number field and using the @@Format option to append the " days" string. That would give you natural sorting.

I missed an invalid character”(”.
I confirmed your script that It does works!!!!!!
Thank you so much Steven!!

No problem. It didn't present any error in the UI: Everytime I refreshed the Issue View though it printed that error in the logs. It's very useful to check the logs when making new script fields. :) Good luck! Happy to help!

I'll check the logs when making new one.

Thank you anyway;)

Hi MISUMI-san, 

I assume you are a Japanese speaker (I am sorry if I am wrong!) and if you feel comfortable asking questions or/and getting answers in Japanese, you can add a tag "Japanese" so that it will be shared with other Japanese users. (Also I am willing to provide translation as a community member if needed!) Hope you find this useful! 

Regards,

Naho Inuyama

Inuyama-san

Thank you for your help.

I added a tag "Japanese"

Naho Inuyama Atlassian Team Jun 14, 2017

You are very welcome! We also have offline user groups in Tokyo, Osaka,Nagoya and Chugoku Area. (and most likely I will be at each event.) It's a great way to share and learn how other peple are using Atlassian products, please join us anytime if you are interested! 

お待ちしております。

Naho Inuyama

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

418 views 7 5
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