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

Andrew Riley December 17, 2012

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

3 votes
Answer accepted
Mizan
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.
December 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

Naren
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.
December 17, 2012

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

0 votes
Andrew Riley December 26, 2012

Thanks Mizan. Much appreciated

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events