How to get year-month only in a calculated text field

Oregional Kft. Atlassian June 1, 2016

Hi

My customer needs a read-only reference field based on JIRA issue key and create date showing only year and month.

Based on this example I tried to do it as shown below, but I get nothing back on the screen. 

What am I doing wrong?

<!-- @@Formula:
createDate=issue.get("created");
if (createDate ==null) return null;
return "M/" +issue.get("issuekey") +string.Format("%tY-%tm", createDate, createDate);
-->

thanks for any hints,

cheers,

gezza

ps: JIRA v7.1.7 with misc custom fields addon v1.7.1

1 answer

1 vote
David _old account_
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 1, 2016

Try String.format instead of string.Format. 

Oregional Kft. Atlassian June 3, 2016

thanks for your answer! I tried it, but it did not help

where can I read about the syntax possibilities? I checked the addon documentation, but it did not provide list of syntax.

I could also use truncation (if such a function exists), eg: to get the year show only the first 4 characters

Is this possible?

David _old account_
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 3, 2016

The syntax is actually documented - or rather pointed to. It's http://www.beanshell.org/docs.html. It is a subset of Java.

As for why it doesn't work for you, the first thing you need to do is check JIRA's logfile (atlassian-jira.log) for errors. Look at the end of the file right after displaying an issue that should show the calculated field.

Oregional Kft. Atlassian June 4, 2016

Hi David,

thanks for your pointers, I managed to solve it!

just for the record I add info below (maybe it helps others)

error in the log:

Sourced file: inline evaluation of: ``  createDate=issue.get("created");  return String.format("%tY", createDate);  ;'' : Error in method invocation: Static method format( java.lang.String, java.sql.Timestamp ) not found in class'java.lang.String' : at Line: 3 : in file: inline evaluation of: ``  createDate=issue.get("created");  return String.format("%tY", createDate);  ;'' : String .format ( "%tY" , createDate )

After some searching, I found this: http://stackoverflow.com/questions/6262570/how-to-retrieve-day-month-and-year-from-timestamplong-format

Based on this the below works fine:

<!-- @@Formula:
createTimestamp = issue.get("created");
long timestamp = createTimestamp.getTime();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
createYear = cal.get(Calendar.YEAR);
return "M/" +issue.get("issuekey") +"/" +createYear;
-->

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events