Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update DueDate

stepstep April 10, 2020

Hi everyone!

Im trying to update DueDate (from customfield + 30 days). I have script listener on update event:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import java.sql.Timestamp;
import java.sql.Date;

def eventIssueKey = event.issue.getKey();
def curIssue = ComponentAccessor.getIssueManager().getIssueObject(eventIssueKey);

def cFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();

def incDate = cFieldManager.getCustomFieldObject("customfield_21553");
def incDateValue = curIssue.getCustomFieldValue(incDate);
def dueDateValue = curIssue.getDueDate();
def dueDateToSet = (Timestamp) incDateValue + 30;

def incDateValueD = Date.valueOf(incDateValue.toLocalDateTime().toLocalDate());
def dueDateValueD = Date.valueOf(dueDateValue.toLocalDateTime().toLocalDate());
def dueDateToSetD = Date.valueOf(dueDateToSet.toLocalDateTime().toLocalDate());

log.warn eventIssueKey;
log.warn incDateValue;
log.warn dueDateValue;
log.warn dueDateToSet;
log.warn dueDateValue.equals(dueDateToSet);
log.warn "casted to date (no time):"
log.warn incDateValueD;
log.warn dueDateValueD;
log.warn dueDateToSetD;
log.warn dueDateValueD.equals(dueDateToSetD);

if (dueDateValueD.equals(dueDateToSetD)) {
log.warn "if -> return";
return;
}

def curUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

curIssue.setDueDate(dueDateToSet);
issueManager.updateIssue(curUser, curIssue , EventDispatchOption.DO_NOT_DISPATCH, false);

log.warn curIssue.getDueDate();
log.warn "updateIssue";

Issue updated -> check if duedate equals customfield + 30 days -> update if false.

When I update issue (like setting another text in summary field) everything works fine.

But when I try to update customfield with workflow button and transition screen duedate doesnt change. At the same time logs and issue history are ok.

 

1.png

2.png

And if I update this issue again it will change.

Is there a way to make it in one transition? Or automaticaly fire one more update event after transtition as workaround?

Thank you!

2 answers

0 votes
stepstep April 17, 2020

Made it with JS custom field in transition screen. It sets duedate in this screen.

0 votes
SITTER Adrien
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.
April 10, 2020

Hello @stepstep

 

I think that may be due to the index that is not been done, try add this updateIssue:

 

boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(curIssue)
ImportUtils.setIndexIssues(wasIndexing)

You are going to need this import:

 

import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService

 Hope it helps

 

Regards,

stepstep April 10, 2020

Thank you for reply.

But result is the same. In logs and history everything ok but in the issue view screen duedate doesnt change.

Suggest an answer

Log in or Sign up to answer