Hello. Can someone do a quick look over on this listener I built?
Purpose: Automatically set the due date when an issue is created. Due Date set is based on which day of the week the ticket was created.
Example: if it was created on a Monday AND does not contain a specific label, set Due Date to Now + 5 days. If the ticket is created any other day of the week AND does not contain a specific label, set Due Date to Now + 6 days.
Here is my listener:
import java.sql.Timestamp;
import java.util.Date;
import java.util.*;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import org.apache.log4j.Category;
import com.atlassian.jira.issue.MutableIssue;
import java.time.LocalDate;
import java.text.SimpleDateFormat;
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.INFO)
Issue issue = event.issue;
MutableIssue myIssue = issue as MutableIssue;
Set issueLabels = issue.getLabels();
boolean containsLabel = false;
Date date = new Date();
long time = date.getTime();
log.info "time = " + time.toString()
issueLabels.each { label ->
if (label.toString().contains("exampleLabel")){
containsLabel = true;
log.info 'containsLabel = ' + containsLabel.toString()
}
}
log.info "Existing Due Date = " + myIssue.getDueDate().toString()
Calendar cal = Calendar.getInstance();
String createdDate = issue.getCreated().toLocalDateTime().format(java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:MM"))
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:MM", java.util.Locale.ENGLISH);
Date myDate = sdf.parse(createdDate.toString());
sdf.applyPattern("EEEE");
def String sMyDate = sdf.format(myDate);
log.info 'Created Date = ' + sMyDate.toString();
if ((sMyDate.toString().contains('Monday') || sMyDate.toString().contains('Sunday')) && issue.issueType.name == "Task" && containsLabel == false && myIssue.getDueDate().toString() == 'null') {
myIssue.setDueDate(new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60));
log.info 'dueDate = ' + myIssue.getDueDate().toString()
}
else if ((!sMyDate.toString().contains('Monday') || !sMyDate.toString().contains('Sunday')) && issue.issueType.name == "Task" && containsLabel == false && myIssue.getDueDate().toString() == 'null') {
myIssue.setDueDate(new Timestamp (cal.getTimeInMillis() + 6 * 1000 * 24 * 60 * 60));
log.info 'dueDate = ' + myIssue.getDueDate().toString()
}
I am able to see the 'dueDate = value' portion in the logs and it is not null, meaning the dueDate variable has been set. However, the issue's Due Date never actually updates. So something must be wrong with:
myIssue.setDueDate( new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60 * 60))