Wow, it's been a while since the last post. Crazy schedule but this one is too cool to ignore! Did you ever want to populate a date field in JIRA but with all the formatting defined in JIRA itself? And maybe add, subtract days etc using javascript? Well, it is easier than you think. And no need to write crazy javascript code to do all the calculations by yourself. Just offload the work to Moment.js! And that is exactly what JIRA does, thanks to Wojciech Urbanski from Atlassian for pointing that out in this post. For example, if you want to set the current date to "due date" in an issue, you can use this: var due = moment(new Date()); var dateString = due.format(JIRA.translateSimpleDateFormat(AJS.Meta.get("date-dmy"))); AJS.$('#duedate').val(dateString); That's all! How about if you want to set the due date 5 days from now? It is again Moment.js that comes to the rescue. var due = moment().add('days', 5); var dateString = due.format(JIRA.translateSimpleDateFormat(AJS.Meta.get("date-dmy"))); AJS.$('#duedate').val(dateString); What about setting the date and time on a datetime custom field instead of just the date? Use date-complete instead of date-dmy. var due = moment(new Date()); var dateString = due.format(JIRA.translateSimpleDateFormat(AJS.Meta.get("date-complete"))); AJS.$('#duedate').val(dateString); You can find the other available formats at atlassian-jira/includes/jquery/plugins/livestamp/moment.jira.i18n.js. Or checkout the page source for more such attributes that can be retrieved via AJS.Meta.get(). Yup, that is what I thought. Cool stuff!
2 Comments
J-Tricks
9/7/2014 01:32:18 am
What if you add the following?
Reply
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorJobin Kuruvilla - Works in Adaptavist as Head of DevOps Professional Services. Categories
All
Archives
October 2016
|