How to add a CF that always has todays date?

Michael Preiss May 7, 2021

Hi,

I am looking for the script to make sure that a custom field e.g. "Today" displays always todays date e.g. May 07, 2021 without making any update on the issue itself.

Can anyone help and explain what to do exactly? Not sure if I have to use a scripted field, behavior or anything else. 

I need to use this field to make a comparison later on between two date fields e.g. "Today" and "Due Date". 

Thanks,

Michael

2 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2021

You can do this with Scriptrunner (I'm taking a guess that you're looking at that because you mention Behaviours), but it's not going to do what you want very well.

This is because of what a field is - the content is something that is part of an issue.  It does not change unless something changes it whether that's code or a human.

If you were to do this with a standard date field, then a script to populate it would be very simple, as all it would need to do is "put now() in custom field".

But, it will set the date to now when it is run.  At midnight tonight, it then becomes wrong, because it's still going to hold today's date.  So you would need to run a second script at midnight to find every issue it is populated on and update the issue, setting the field to the new date.

On server, you have the option of a scripted field, with a script behind it that's not a lot more complex than "return now()"

But again, that is fixed data and you'll need to update it at midnight every night.  With a scripted field, you can have less impact - they don't store their data in the database and you can trigger and update with some code that just triggers a re-index on the issue without changing it.

Either way though, you're having to perform potentially large updates every night.

I would forget it and look at the comparison you are doing instead.   Usually, people are doing comparisons in JQL, and that doesn't need a field to do what I think you are looking for.  For example 

duedate > now()

will list all issues with a due date after today.

Michael Preiss May 7, 2021

Many thanks for your response, Nic. Have a nice weekend

0 votes
Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2021

I am wondering if you could use automation to achieve your goal. Are use automation in some rules to compare a date to today’s date without having to have a custom field displays today’s date. You might check the Automation documentation for this. 

Michael Preiss May 7, 2021

Hi Jack, many thanks.

We have JIRA server and according to Atlassian, automation is not actively available for Server customers....

Alternatively, I am also fine if another CF "Delayed?" displays "Yes" or "No".

Can you help?

Michael

Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2021

Sorry I missed that you were on server. You’re gonna need some sort of ad on the manage these dates and custom fields. Not a ure I can really help you beyond that. 

Suggest an answer

Log in or Sign up to answer