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 votes
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,864 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot