How to use the Calculated text field

MISUMI servicedesk June 13, 2017

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

3 votes
Answer accepted
Steven Behnke
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.
June 13, 2017

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.

MISUMI servicedesk June 13, 2017

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?

Steven Behnke
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.
June 13, 2017

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

Steven Behnke
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.
June 13, 2017

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.

MISUMI servicedesk June 13, 2017
I missed an invalid character”(”.
I confirmed your script that It does works!!!!!!
Thank you so much Steven!!
Steven Behnke
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.
June 13, 2017

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!

MISUMI servicedesk June 14, 2017

I'll check the logs when making new one.

Thank you anyway;)

3 votes
naaho
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2017

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

MISUMI servicedesk June 14, 2017

Inuyama-san

Thank you for your help.

I added a tag "Japanese"

naaho
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 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