It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to overwrite due date system field using groovy.

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

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))
}

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

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

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
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you