Update Due Date

Hi guys,

I am trying to update the due date with a groovy script. I have found different solutions on the community but it doesn't work for me. 

I have the following error : groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.DocumentIssueImpl.setDueDate() is applicable for argument types: (java.sql.Timestamp) values: [2017-09-20 13:54:25.408] Possible solutions: getDueDate()

I don't find the method setDueDate in the last Jira Api, is it depreciated ? 

And when I try to directly modify the value 

it.dueDate = mydueDate

, I have an error message which says that the value is read only.

Any idea ? Here is my code ?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserUtils
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.web.bean.PagerFilter
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp


ComponentManager componentManager = ComponentManager.getInstance()
IssueManager issueManager = ComponentAccessor.getIssueManager()
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );


String userString = UserUtils.getUser('admin').name

def jqlSearch = "project = 'RPD'"
List<Issue> issues = null
def newRPDDate = customFieldManager.getCustomFieldObject((long) 27800)

SearchService.ParseResult parseResult =  searchService.parseQuery(user, jqlSearch)

if (parseResult.isValid()) {
    def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
    issues = searchResult.getIssues()
    for(Issue it : issues){
        /*workflowTransitionUtil.setIssue(it);
        workflowTransitionUtil.setUsername(user);
        workflowTransitionUtil.setAction (51)*/
        Calendar myCalendar = Calendar.getInstance()
        myCalendar.setTime(it.getDueDate())
        myCalendar.add(Calendar.MONTH,3)

        //String[] splited = it.getDueDate().toString().split("\\s+");
        Timestamp mydueDate = new Timestamp(myCalendar.getTimeInMillis()+ 90*1000*24*60*60)
        //it.setDueDate(new Timestamp(myCalendar.getTime().time))
        it.setDueDate(mydueDate)
        //it.dueDate = mydueDate
        return it.dueDate

        return it.key
        return splited[0]
    }
}

1 answer

1 accepted

Accepted Answer
0 votes

I have understand my mistake, this method works with the MutableIssue. I need to cast my objects DocumentIssueImpl to MutableIssue to use the method but I don't know how to do it.

I have change my request to get IssueImpl and it works well now.

I put my code here if it can help someone :

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserUtils
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.web.bean.PagerFilter
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp


ComponentManager componentManager = ComponentManager.getInstance()
IssueManager issueManager = ComponentAccessor.getIssueManager()
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );


String userString = UserUtils.getUser('admin').name

def jqlSearch = "project = 'RPD' AND issuetype = Task"
List<Issue> issues = null
def newRPDDate = customFieldManager.getCustomFieldObject((long) 27800)

SearchService.ParseResult parseResult =  searchService.parseQuery(user, jqlSearch)

if (parseResult.isValid()) {
    def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
    issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }
    for(Issue it : issues){
        workflowTransitionUtil.setIssue(it);
        workflowTransitionUtil.setUsername(user);
        workflowTransitionUtil.setAction (51)
        Calendar myCalendar = Calendar.getInstance()
        myCalendar.setTime(it.getDueDate())
        myCalendar.add(Calendar.MONTH,3)

        it.setDueDate(new Timestamp(myCalendar.getTime().time))
        it.store()


       // return it.key
    }
}

Would this make it so that the due date goes up every day even whn using the card repater?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,981 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you