Calculated date/time field

Hi! I'm using JIRA 6.3.9

 

I'm trying to create date field, that will count time in city

For example:

In field "city" i set "Paris"

In field "Date in city" i get "20/oct/14 6:55 PM"

 

I tryed to set some formulas, but i've got 2 problems:

1) <!-- @@Formula: org.apache.commons.lang.time.DateUtils.addHours(new Date(),10) --> does not work (i get "10 hours" instead of date)

2) How can i set cascade for >2 values (if "Paris" then ... if "London" then...)

1 answer

1 accepted

This widget could not be displayed.

1) this is normal, as JIRA displays dates in a user-friendly manner when they are close to now. So "ten hours from now" will be displayed as "in 10 hours".

2) you can use a cascade of i/else:

String city = issue.get("customfield_12345");
if ("Paris".equalsIgnoreCase(city))
	return org.apache.commons.lang.time.DateUtils.addHours(new Date(),10);
if ("London".equalsIgnoreCase(city))
	return org.apache.commons.lang.time.DateUtils.addHours(new Date(),9);
[...]

Note that if field 12345 is of type Select list (a combobox), then the first line should read:

String city = issue.get("customfield_12345").getValue();

And you might want to protect against null value for city 

1) I understand 2) not working. Maybe i did something wrong? (field is not picker, just text field) <!-- @@Formula: String city = issue.get("customfield_10400") if ("Paris".equalsIgnoreCase(city)) return org.apache.commons.lang.time.DateUtils.addHours(new Date(),10); if ("London".equalsIgnoreCase(city)) return org.apache.commons.lang.time.DateUtils.addHours(new Date(),9); -->

Sorry, I forgot a semicolon at the end of the first line. In general, if it doesn't work, it might be a syntax error and you will see it in atlassian-jira.log

Wow! now it works great!!! Thanks! You are my hero now!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

125 views 2 0
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