Hello everybody. I try to make Script Listener, which in the time of issue creation set in custom field time which is created time + 2 hours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
def createTime = event.issue.created
log.warn("Created at : " + createTime)
def cfManager = ComponentAccessor.getCustomFieldManager()
def cfField = cfManager.getCustomFieldObject("customfield_34850")
def fieldValue = event.issue.getCustomFieldValue(cfField)
def newTime = new Timestamp(createTime.time)
Long duration = ((120 * 60) + 00) * 1000;
newTime.setTime(newTime.getTime() + duration);
MutableIssue issueToUpdate = (MutableIssue) event.issue
issueToUpdate.setCustomFieldValue(cfField, newTime)
IssueManager issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(event.getUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false)
But have error in last line
java.lang.String cannot be cast to java.util.Date
Where have I made mistake?
Hi aas
Try this:
def newTime = event.issue.created
def newHours = event.issue.created.getHours() + 2
newTime.setHours(newHours)
It also works if the hours pass midnight (new day is set).
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.