Set issue Due Date based on priority

David Thompson August 27, 2013

Hi,

I would like to add a post function to newly created issues to set the due date based on the priority of the issue.

I have tested out a groovy script from an author called "mizan" but it fails to work for me as I get errors in the logs, plus the script seems to have down the rounds on a few forums and been chopped and changed etc so hard to know what isa clean working version.

Hopefully someone has a nice solution to this?

Thanks,

David

5 answers

1 accepted

0 votes
Answer accepted
David Thompson August 28, 2013

Investigatiing more, I relalised the priority names had been changed from the default. I updated the script and it worked fine.

Thanks for your input.

David

0 votes
Christopher Gronde October 14, 2016

Has anyone out there successfully made this work?  I have seen several different people post very similar scripts but all the comments say they still get errors. 

0 votes
Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

Just guessing but it seems that you are trying to calculate the time based on the system time / creation time? The object you are trying to adress obviously doesn't exist yet. When do you fire that post function? Maybe before the issue has been created and indexed? Try to set the post-function to be the last action...

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

And I guess posting the script wouldn't be a bad idea either ;-)

Cheers Christian

David Thompson August 28, 2013

Hi Christian,

I'm hoping to set the due date on the creation of the issue. I will hide the due date field from the create issue screen so users can't set it.

Cheers,

David

The code is below;

import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue

// initializing the priority

def BLOCKER = 1;
def CRITICAL = 2;
def MAJOR = 3;
def MINOR = 9;
def Trivial = 30;

// calender which returns the date according to the priority defined

private GregorianCalendar getDate(double roll)
{
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        cal.set(Calendar.MILLISECOND,0);

        for (int x=0;x<roll;x++)
{
                cal.add(Calendar.DAY_OF_MONTH,1);
           }

        return cal;
}

MutableIssue mutableIssue = (MutableIssue) issue;
def priority = mutableIssue.getPriority().getString("name");
def setDueDate = mutableIssue.getDueDate();
 //only set the dueDate if the date isn't already set (i.e. if it == null).

        GregorianCalendar cal;

         if(priority.equals("Critical"))
{
                cal = getDate(CRITICAL);
           }
   else if(priority.equals("Major"))
{
                cal = getDate(MAJOR);
           }
   else if(priority.equals("Minor"))
{
                cal = getDate(MINOR);
           }
        Timestamp dueDate = new Timestamp(cal.getTimeInMillis());
        mutableIssue.getPriorityObject();
        mutableIssue.setDueDate(dueDate);

Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

Have you checked the order of your post-functions?

David Thompson August 28, 2013

I have put this post function as the last in the order.

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

if you hide the field in field configuration then you can't set value to that field

!!

David Thompson August 28, 2013

Hi Rambanam,

To confirm, the due date field is visible for the create, Once I had this working I was goign to atempt to hide it. I have also checked the screens and the due date field is visible for "view" and "edit".

Thanks,

David

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

just for confirmation,did you tried by adding post function before create issue function?

David Thompson August 28, 2013

Yep, it still displays the same error.

0 votes
David Thompson August 28, 2013

Hi Timothy,

the error I get starts with the below;

2013-08-29 10:38:53,088 http-8090-2 ERROR user1 638x187x1 1ksoqu2 10.99.0.103,127.0.0.1 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTimeInMillis() on null object
2013-08-29 10:38:53,091 http-8090-2 ERROR user1 638x187x1 1ksoqu2 10.99.0.103,127.0.0.1 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTimeInMillis() on null object
.jira.web.action.issue.CreateIssueDetails.createIssue(CreateIssueDetails.java:95)


Thanks,

David

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2013

So? What is the error?

Suggest an answer

Log in or Sign up to answer