Scriptrunner listener updates not showing in Issue History Edited

Hi,

I have the following script listener to update a User Picker field (Accepted By) and Date Time field (Accepted Date) with current user and current timestamp when a user populates a checkbox called P.O. Accepted.

Assistance for the script was provided by @Thanos Batagiannis [Adaptavist] in Scriptrunner-listener-to-update-custom-date-time-field (again thank you Thanos!)

The script does the 2 updates as required, however the issue history tab does not show that the Accepted By & Accepted Date fields have been updated. It only shows that the checkbox field (P.O. Accepted) that triggers the updates of both these fields has been changed.

What am i missing/doing wrong?

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 com.atlassian.jira.issue.customfields.manager.OptionsManager
import java.sql.Timestamp 

Issue issue = issue 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "P.O. Accepted"} 
if (change) {       
if (change.newstring == "Accepted as Done")
{
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Accepted Date")   
def changeHolder = new DefaultIssueChangeHolder()   
def now = new Timestamp(new Date().getTime())   
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), now),changeHolder)       
def cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Accepted By")   
def changeHolder2 = new DefaultIssueChangeHolder()   
cf2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf2), currentUser),changeHolder2)
}   


if (change.newstring != "Accepted as Done")

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Accepted Date")   
def changeHolder = new DefaultIssueChangeHolder()   
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), null),changeHolder)       
def cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Accepted By")   
def changeHolder2 = new DefaultIssueChangeHolder()   
cf2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf2), null),changeHolder2)
}
}

Many thanks in advance,

Conor

1 answer

This widget could not be displayed.
Gaston Valente Community Champion Sep 08, 2017

Conor,

Maybe it's because the second parameter of ModifiedValue is null.

You can try to use IssueService to perform this tasks easier too!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

593 views 25 15
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