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.
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!
Made it with JS custom field in transition screen. It sets duedate in this screen.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.