How to overwrite due date system field using groovy.

Susheela Kushwaha December 4, 2019

Hi,

I am trying to overwrite issue Due date but the new due date value do not reflect on the issue. Can you please suggest how to over write system fields in JIRA?

if(issuePriority == "Critical"){

issue.setDueDate( new Timestamp((new Date() + 1).time))
}

There is no error logged by log.error()  but I still see old due date on the issue after running above code. Please help!

1 answer

0 votes
Damian Wodzinski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2019

So the srcipt runs correctly, but the date is not updated? Tre reindexing the issue:

issueIndexingService.reIndex(Issue issue).

 

Also I would try to put log error after if, to see if the condition was met:

if(issuePriority == "Critical"){
log.error("Condition passed")
issue.setDueDate( new Timestamp((new Date() + 1).time))
}

Susheela Kushwaha December 6, 2019

Thanks Damian. Will re-indexing issue each time it is updated, affect the JIRA performance? Will it increase CPU usage?

Damian Wodzinski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2019

No, its only one Issue and it is reindexed only once, when script fire it up.

Susheela Kushwaha December 9, 2019

Tried re-indexing. Log shows updated date but the system due date field still holds the old value:

Here is my script:

import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils


IssueManager issueManager = ComponentAccessor.getIssueManager()

IssueIndexingService issueIndexService = ComponentAccessor.getComponent(IssueIndexingService.class);
MutableIssue issue = event.issue as MutableIssue
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

def iPriority = issue.getPriority().name

if(iPriority == "Critical"){
log.error("Condition passed")
issue.setDueDate( new Timestamp((new Date() + 1).time))
}
else if(iPriority == "High"){
log.error("Condition passed")
issue.setDueDate( new Timestamp((new Date() + 4).time))
}

log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));

log.error(issue.getPriority().name)
log.error(issue.getDueDate())

----------------------------------------------------------------

Created an issue with Due date = 9 Dec 2019

Here is the log result:

2019-12-09 14:21:45,677 ERROR [runner.AbstractScriptRunner]: Condition passed
2019-12-09 14:21:45,678 WARN [runner.AbstractScriptRunner]: Reindex issue MKT-10 36901
2019-12-09 14:21:45,747 ERROR [runner.AbstractScriptRunner]: High
2019-12-09 14:21:45,747 ERROR [runner.AbstractScriptRunner]: 2019-12-13 14:21:45.678

But, I still see old due date on the ticket. 

Suggest an answer

Log in or Sign up to answer