Using JIRA Server 7.3.2
In my release notes, I'd like the current date and time at the bottom. E.g. just to echo out "2017-09-28T12:45" for example.
Is that possible using the Velocity templates? I know how to edit the template and all - so I'm just after the syntax / method on how to obtain the current date and time. Preferred also if there is an UTC variant?
I'm using Jira Server 8.2.3, and I tried using $dateUtil.getCurrentDate() and other options, but none of them worked. After giving up on this matter for a few months, I decided to use javascript.
Considering a scenario similar to the example in the docs, where you have a textarea element which can be copied, you would add the following code to your template:
<script>
window.onload = () => {
const today = new Date();
let day = today.getDate().toString();
day = day.length > 1 ? day : '0' + day;
let month = (1 + today.getMonth()).toString();
month = month.length > 1 ? month : '0' + month;
const year = today.getFullYear();
const formattedToday = `${day}/${month}/${year}`;
const currentChangelog = document.getElementById("changelogText");
currentChangelog.value = `Changelog - ${formattedToday}\n${currentChangelog.value}`;
};
</script>
In this scenario, you would have a textarea with its id as changelogText, and date format as dd/MM/YYYY. So, if you have a changelog similar to the text below:
Task
- [[TK-1]](http://localhost:8080/browse/TK-1) - Kanban cards represent work items >> Click the "TK-1" link at the top of this card to show the Detail view - there's more on Kanban in the 'Description' section
Bug
- [[TK-3]](http://localhost:8080/browse/TK-3) - Add work items with "+ Create Issue" at the top right of the screen >> Try adding a new card now
After adding the javascript code, you would get:
Changelog - 14/08/2020
Task
- [[TK-1]](http://localhost:8080/browse/TK-1) - Kanban cards represent work items >> Click the "TK-1" link at the top of this card to show the Detail view - there's more on Kanban in the 'Description' section
Bug
- [[TK-3]](http://localhost:8080/browse/TK-3) - Add work items with "+ Create Issue" at the top right of the screen >> Try adding a new card now
Of course, if you want to change how you will display date (and time, if you prefer), you need to manipulate your Date object differently than above. For that, I recommend reading this Mozilla documentation.
Note: This solution uses client-side javascript, so if your server time is different from your users, this code will not help.
You don't really do it in velocity, you call out to Java to do it.
From memory, start with $dateUtil.getCurrentDate()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic,
I actually tried this already - but it just renders like this:
Release notes generated $dateUtil.getCurrentDate()
So it doesn't "execute" the java call. I guess that means dateUtil is not in the current VelocityContext.
Docs are not that good as to what context classes I have access to :(
Any pointers?
BTW: I've also been trying the docs here. There it is called "dateutils". I've also tried the link to JIRA 3.6.x and later, but that points to Email context. very confusing. In any case - whatever I try, it is just rendered as text.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ran into similar issues, Werner. You are not alone.
I wonder what is in the Velocity context for Jira's release notes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.