We are using script runner.
The needed behaviour is:
Everytime the severity level is changed, we need to set the due date based on the created date plus the level business days.
In short i need the following steps.
- Get createdDate
- Get severity timePeriod
- Add days for weekends in createdDate + timePeriod
- Update dueDate with added days
I found the following script but cannot get it to work with the created date and the business days.
import java.sql.Timestamp
def severityLevel = getFieldById(fieldChanged)
def severityLevelValue = severityLevel.value.toString()
def dueDateField = getFieldById("duedate")
def days = 24*60*60*1000 // number of milliseconds in a day
def updatedDate = new Date()
def timePeriod // to pass the number of days.
if (severityLevelValue == "1") {
timePeriod = 8
} else if (severityLevelValue == "2") {
timePeriod = 12
} else if (severityLevelValue == "3") {
timePeriod = 20
} else return null
updatedDate.setTime(new Timestamp(System.currentTimeMillis() + timePeriod * days).time)
dueDateField.setFormValue(updatedDate.format("dd/MMMM/yyyy"))
This script is based on current date and not the created date. It seems to me, that i cannot get the created date as timestamp format as basis for the calculation.
Also adding of days for the weekends is missing. I found this code snippet for the business days:
Calendar c1 = GregorianCalendar.getInstance();
c1.setTime(new Date())
for(int i=1;i<=timePeriod;i++){
c1.add(Calendar.DAY_OF_MONTH, 1);
if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
c1.add(Calendar.DAY_OF_MONTH, 1);
if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
c1.add(Calendar.DAY_OF_MONTH, 1);
}
c1.clearTime().getTime().toTimestamp()
How can i combine this with the script before?
Your help is very much appreciated.