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

This widget could not be displayed.
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();
        todaysDate.setHours(0,0,0,0);
        if (dueDate <= todaysDate) {
          jQuery("#duedate").val("");
          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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

264 views 1 3
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