Scriptrunner listener to update custom date/time field

Hi All,

I need to write a listener that will add current timestamp to a custom date/time fields when another field is updated.

For example, if custom checkbox "Approved" is set, the listener detects this change and will timestamp the custom date/time field "Approved Date".

I had intended to simply do this through the JIRA Suites Utility plugin on a workflow transition, but the requirements have changed and this needs to be done on an "Edit" and hence needs to be detected and updated by a custom listener.

 Can @Thanos Batagiannis [Adaptavist] , @Jamie Echlin [Adaptavist] or some of the other Adaptavist guys please help me out here?

Any help is much appreciated.

Regards,

Conor

 

1 answer

1 accepted

Accepted Answer
7 votes

Hi Conor,

Try something like 

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 == "CheckBox A"}
if (change) {
    def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved DateTime")
    def changeHolder = new DefaultIssueChangeHolder()
    def now = new Timestamp(new Date().getTime())
    cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), now),changeHolder)
}

Please let me know if this does the trick.

regards, Thanos

Hi @Thanos Batagiannis [Adaptavist], thank you for that great assistance. I was about to accept the answer smile until I hit a real roadblock - the listener isn't firing when I try to bulk transition issues!

There will be occasions when I want to bulk edit closed issues to update these fields, restricting it to the Product Owner role.

To do this I intended to add a transition to loop from Closed to Closed and call it "Product Owner Update". This would present the screen to allow for the fields to be updated. All of this works when working on a single issue, but when I try to bulk transition (update) a set of Closed issues the transition does not fire sad 

 

 

 

 

Hi Conor, 

How do you bulk update the issues ?

I'm trying to bulk update Closed issues in this scenario, so I'm actually bulk transitioning (Closed to Closed) via a transition that is restricted to a limited set of users

 

image2017-2-15 15:10:19.png

 

The transition fires the "Issue Updated" event which the listener picks up. Works on single issues, but doesn't fire or isn't detected when doing bulk transitions

these status properties are my saviour, and I can now edit closed (bulk edit even) and do not need to do it via bulk transitions

 

image2017-2-15 17:0:24.png

 

 

Can I perform the operation with a text field instead of a Checkbox?

Can any one guide me to any resources or the code?

any help is appreciated.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

25,536 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you