Set issue Due Date based on priority

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

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 vote
Timothy Chin Community Champion Aug 28, 2013

So? What is the error?

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

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...

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

Cheers Christian

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);

Have you checked the order of your post-functions?

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

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

!!

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

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

Yep, it still displays the same error.

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. 

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 ...

3,327 views 14 20
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