Creating a read only due date field that auto populates when creating an issue

With different issue types we have put in place different SLA's. I want JIRA to manage the due dates for the SLA's based on issue type. For example when someone creates an issue with issue type Question the SLA to answer this question and resolve the issue is 3 days from the issue being created. I want the field to display in the issue but not allow it to be edited by anyone in jira-users other than people in jira-administrators group.

I have tried using the read only text field and then try to configure it somehow to auto populate but could not work out how.

Any help you could give would be greatly appreciated.

Thanks, Andrew

2 answers

1 accepted

This widget could not be displayed.
Mizan Community Champion Dec 17, 2012

You will need to create a post function or a post function groovy script with script runner plugin which will check the issue type and set the Due date of the Issue , Also you will need to make the due date field as read only for this you can use the behaviours plugin which can make a field as read only .

Refer the below groovy script example for setting the due date

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

Also refer this post for making a field read only

In this case, you need to define the condition in the above script based on Issue Type and not on Priority

def issueType = mutableIssue.getIssueType().getString("Question");

So the above script can be modified to the below one and run it as a post function by adding this script to the Create Issue transition-

def BUG = 1; 
def TASK = 2; 
def IMPROVEMENT = 3; 
def QUESTION = 9; 
....
....

if(issueType.equals("Bug"))
{                
	cal = getDate(BUG);         
}
else if(issueType.equals("Task"))
{                 
	cal = getDate(TASK);         
} 
else if(issueType.equals("Improvement"))
{                 
	cal = getDate(IMPROVEMENT);         
}
else if(issueType.equals("Question"))
{
	cal = getDate(QUESTION);
}

This widget could not be displayed.

Thanks Mizan. Much appreciated

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in United States

Local Atlassian Research Workshop opportunity on Sep. 28th

We're looking for participants for another workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sh...

35 views 0 0
View post

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