Hi,
I'm trying to set a due date for an issue as 30 days after the issue on issue create - specifically the first weekday 30 days after today. Using the script from Warren McInnes at https://answers.atlassian.com/questions/135802 (comment dated Feb 11, 2014), I have run into a peculiar issue. I can set the due date for any number up to 24 (twenty four) days in the future, however, if I set the variable days to any value >= 25, it ends up setting a due date in the past - appears to subtract this value.
Again, today is November 4 (Friday), 24 days in the future is November 28 (Monday) -> With the script as days = 24, JIRA creates the issue with a due date of 28/Nov/16.
With the script as days = 25, JIRA creates the issue with a due date of 10/Oct/15, that is, in the past (?coincidence 25 days).
Most important question is - can anyone reproduce this? Or is Friday getting to me?
Workflow has the following post functions on create:
- ScriptRunner workflow function - Custom script post-function (inline script).
- Creates the issue originally.
- Re-index
- Fire an Issue Created event.
import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp;
int days = 25;
log.info("var days: "+days.toString());
int dayOfWeek = 0;
Date today = new Date();
MutableIssue myIssue = issue
Calendar dueDate = Calendar.getInstance();
while ((dayOfWeek == 0) || (dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)) {
dueDate.setTimeInMillis(today.getTime() + days*1000*24*60*60);
dayOfWeek = dueDate.get(Calendar.DAY_OF_WEEK);
days = days + 1;
log.info("Days in loop: "+days.toString());
}
System.out.println("script setduedate is running...and mydueDate is:" + dueDate.getTime());
log.info("Day of week: "+dayOfWeek.toString()+", Day: "+days.toString()+", Due Date: "+dueDate.getTime());
myIssue.setDueDate(new Timestamp(dueDate.getTime().getTime()));Running JIRA server 7.1.7 (software/core 7.1.7 and JIRA SD 3.1.7).
Script appears to run (Script runner doesn't say failure + no due date on create screen, but one is being set).
Alternatively, if anyone has any other ideas on how to set a due date on issue create on the first weekday after 30 days, that would also be appreciated 