How to permanently set DueDate in JIRA using Groovy script?

I’m having a hard time with a Groovy script in JIRA. We’re trying to fix a problem where the status resets every week. The script is supposed to change the DueDate field to 7 days from when it runs. It looks like it’s working because it shows the right date, but it’s not actually saving it for the issue.

Here’s what I’ve got so far:

import java.util.Calendar
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject('MYISSUE-123')

def calendar = Calendar.instance
calendar.add(Calendar.DAY_OF_YEAR, 7)
def newDueDate = calendar.time

issue.dueDate = newDueDate
issue.store()

println issue.dueDate

The script runs without errors and prints the new date, but when I check the issue, the DueDate hasn’t changed. What am I missing? Is there something else I need to do to make sure it saves?

I’ve dealt with this exact problem before, and it can be frustrating. The issue is likely related to how JIRA handles field updates. Instead of using issue.store(), try using the IssueService to update the issue. Here’s a modified version of your script that should work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService

def issueService = ComponentAccessor.getIssueService()
def issue = ComponentAccessor.issueManager.getIssueObject('MYISSUE-123')
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def newDueDate = new Date() + 7

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setDueDate(newDueDate)

def updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (updateValidationResult.valid) {
    def updateResult = issueService.update(user, updateValidationResult)
    if (updateResult.errorCollection.hasAnyErrors()) {
        println "Error updating issue: ${updateResult.errorCollection}"
    } else {
        println "Issue updated successfully. New due date: ${issue.dueDate}"
    }
} else {
    println "Validation failed: ${updateValidationResult.errorCollection}"
}

This approach uses the IssueService to validate and update the issue, which should properly persist the changes. Let me know if you encounter any issues with this solution.

I’ve encountered this problem before, and it’s often related to how JIRA handles field updates in scripts. The store() method doesn’t always work as expected for certain fields. Instead, try using the IssueManager’s updateIssue() method. Here’s a modified version of your script that should work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject('MYISSUE-123')

def newDueDate = new Date() + 7

issue.setDueDate(newDueDate)
issueManager.updateIssue(ComponentAccessor.jiraAuthenticationContext.loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

println \"Updated due date: ${issue.dueDate}\"

This approach should properly update and persist the due date. Make sure you have the necessary permissions to modify the issue. If you’re still having trouble, check the JIRA logs for any error messages that might provide more insight.

hey sophiac, i had a similar issue. try using the updateIssue() method instead of store(). it worked for me. also, make sure you have the right permissions to modify the issue. sometimes that can trip you up. good luck with your script!