Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Date of last update on a custom field

Jorge
Contributor
June 6, 2022

Hello!

I need some help with grabbing the date (yyyy-mm-dd) of the last time a custom field was updated, nothing fancy just the date to display it on a dashboard for managers.

I appreciate the help.

 

1 answer

1 accepted

1 vote
Answer accepted
Mark Segall
Community Champion
June 6, 2022

Hi @Jorge - Jira does not provide a native mechanism to query against history so you'd need a 3rd party tool like script runner.

Jorge
Contributor
October 21, 2022

Thanks, I was able to pull this of with Scriptrunner

Like Judah likes this
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2022

@Jorge - How did you do this with ScriptRunner? 

Jorge
Contributor
December 16, 2022

Hi Judah,

I used a script field:

 

import com.atlassian.jira.component.ComponentAccessor
final String customFieldName = "Your_custom_field_name"
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def changeHistory = changeHistoryManager.getChangeItemsForField(issue, customFieldName)
log.warn(changeHistory)

try{
def changedate = changeHistory.last()?.getCreated().getDateString()
log.warn(changedate)
return changedate
}
catch (Exception e){}
Like # people like this
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2022


@Jorge Thanks for sharing your code! I also used a SR Scripted Field: Date Time Range picker, Custom template (so I could manipulate the date format), I also added some logic to hide the script field if another field has no value.  

Custom Template: 

 

$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value).toString()

 

 

Script: 

 

import com.atlassian.jira.component.ComponentAccessor

// To get the Status Comments field

def statusCommentsField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Status Comments')[0]

// To get the Status Comments field value for an issue

def statusCommentsValue = issue.getCustomFieldValue(statusCommentsField)

// To get the Status Comments field's changes

def lastComment = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, 'Status Comments')

if(!statusCommentsValue){ // If Status Comments field is empty or has no value

    return null

}else{

    if(lastComment){ // If the Status Comments field has change history record(s)

        return lastComment.last().getCreated()

    }

}
 
Like # people like this
Jorge
Contributor
December 29, 2022

Nice work!

Like Judah likes this

Suggest an answer

Log in or Sign up to answer