Integration with Script Runner

Services of “Issue Reminders” app can be accessed by Script Runner and other plugins. You can browse Issue Reminders JavaDoc for available services. You can use this feature to create automatic reminders when status of an issue is changed.

 

Creating a New Reminder

Following script adds a new Reminder for assignee of the issue. Reminder is scheduled after 3 days when the issue is transitioned.

import java.time.*; import java.time.temporal.ChronoUnit; import java.util.Date; import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.deniz.jira.reminders.service.ReminderService; import com.deniz.jira.reminders.data.*; import com.atlassian.jira.component.ComponentAccessor def project = issue.getProjectObject() @WithPlugin("com.deniz.jira.reminders") // Inject plugin module @PluginModule ReminderService reminderService; def ReminderImp reminder = new ReminderImp(); reminder.summary = "the time has come"; reminder.longDescription = "Issue reached reminder-date!"; reminder.issueId = issue.id; Instant inst = Instant.now().plus(3,ChronoUnit.DAYS); reminder.reminderDate = Date.from(inst); def target = new ReminderTargetImp(); target.identifier = issue.assignee.key; target.targetType = ReminderTarget.ReminderTargetType.USER; reminder.addReminderTarget(target); reminderService.addReminder(reminder);

 

Deleting Existing Reminders of The Issue

Following script deletes reminders of the issue, if the issue is resolved. You can set this script as a post function for Done/Resolve transition and remove reminders of the issue. So that reminders do not fire for resolved issues. Note that since this script checks issue resolution you have to place this post function below the “Update Issue Fields” post function which sets resolution of the issue.

 

import java.time.*; import java.time.temporal.ChronoUnit; import java.util.Date; import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.deniz.jira.reminders.service.ReminderService; import com.deniz.jira.reminders.data.*; import com.atlassian.jira.component.ComponentAccessor @WithPlugin("com.deniz.jira.reminders") // Inject plugin module @PluginModule ReminderService reminderService; if (issue.getResolution() != null) { //delete reminders only if issue is resolved def remindersForIssue = reminderService.getRemindersForIssue(issue.getKey()); remindersForIssue.each { reminderService.deleteReminder(it.id) } }