Use Javascript to compare date?

I have a custom field that is called "estimated issue close date". If the estimated issue close date has past, I want the field to clear or show a message or do something when the user goes to edit the issue so they must change the date. I can't add a validator because I want it to happen on Edit and there is no workflow transition for that. How can I accomplish it with javascript? Also, I do not have permission to make custom plugins

1 answer

0 vote
Stephen Deutsch Community Champion Jun 18, 2015

Hi Kelsey,

You would have to include some javascript in the announcement banner.  Here is an example that might get you started.  It doesn't filter by project, so this would be active for all projects.  Also, this one uses the due date field.  If you want to use it for your particular due date field, you would have to change "#duedate" to "#customfield_XXXXX" (you would have to look using "Inspect Element" and find the id).  This also assumes your date format is 1/Jan/15. The results of this script are that if the due date is prior to the current date, then an alert is shown and the field is cleared.

jQuery(document).ready(function() {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
        var dueDate = jQuery("#duedate").val();
        dueDate = Date.parse(dueDate.substring(2, 5) + " " + dueDate.substring(0, dueDate.indexOf("/")) + ", 20" + dueDate.substring(6, 8));
        var todaysDate = new Date();
        if (dueDate <= todaysDate) {
          alert("The previously selected due date has passed. Please enter a new due date.");

I hope you can figure out how to modify to fit your needs. Don't forget to wrap it in <script> tags.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

486 views 3 11
Read article

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