Hi All,
I need a listener that will add current timestamp (date or datetime) to a custom date/time fields when another field (Story Points) is updated, for JIRA Cloud.
For example, if custom checkbox "Story Points" is edited, the listener detects this change and will timestamp the custom date/time field "StoryPointsLastChangeDate".
And, should the StoryPointsLastChangeDate a 'date' field or a 'datetime' custom field?
Thanks to @Conor McGmail @Thanos Batagiannis _Adaptavist_ .
I fond your post at : https://community.atlassian.com/t5/Jira-questions/Scriptrunner-listener-to-update-custom-date-time-field/qaq-p/387444
But for JIRA Cloud, it does not work.
my script listner:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.sql.Timestamp
Issue issue = issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Story Points"}
if (change) {
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("StoryPointsLastChangeDate")
def changeHolder = new DefaultIssueChangeHolder()
def now = new Timestamp(new Date().getTime())
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), now),changeHolder)
}
The errors:
2017-11-02 03:20:45.232 ERROR - startup failed:
Script1.groovy: 3: unable to resolve class com.atlassian.jira.issue.ModifiedValue
@ line 3, column 1.
import com.atlassian.jira.issue.ModifiedValue
^
Script1.groovy: 2: unable to resolve class com.atlassian.jira.issue.Issue
@ line 2, column 1.
import com.atlassian.jira.issue.Issue
^
Script1.groovy: 1: unable to resolve class com.atlassian.jira.component.ComponentAccessor
@ line 1, column 1.
import com.atlassian.jira.component.ComponentAccessor
^
Script1.groovy: 4: unable to resolve class com.atlassian.jira.issue.util.DefaultIssueChangeHolder
@ line 4, column 1.
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
^
4 errors
2017-11-02 03:20:45.653 ERROR - Class: com.adaptavist.sr.cloud.events.ScriptExecution, Config: null
Any help is much appreciated.
Regards,
Darren