I've set up a listener in scriptrunner to add 5 days to a date picker field every time the assignee field is changed. It isn't working...and I'm not sure where the failure is. The events it fires on are, Issue Created, Issue Updated, Issue Assigned. It is not failing, but it also isn't doing what I need it to do.
Is a listener a viable way to make this work? I didn't think post functions would, so I was hoping a listener could do the job.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import java.util.Date
import java.text.SimpleDateFormat
import java.util.Calendar
def issue = event.issue as MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find{ it.field == "assignee"}
// check if the "assignee" field was changed
if (change) {
// get the custom field object by name
def baselineEndField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Baseline End")
// check if the custom field is present on the issue and has a value
if (issue.getCustomFieldValue(baselineEndField) instanceof Date) {
// get the current value of the custom field
Date baselineEnd = issue.getCustomFieldValue(baselineEndField)
// add 5 days to the custom field
Calendar calendar = Calendar.getInstance()
calendar.setTime(baselineEnd)
calendar.add(Calendar.DATE, 5)
Date newBaselineEnd = calendar.getTime()
// set the new value of the custom field
issue.setCustomFieldValue(baselineEndField, newBaselineEnd)
}
}