Forums

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

How to find out when a customfield was last updated ?

Lokesh
Contributor
September 17, 2021

We need to reduce total count of fields in-use in a project.

Need to find out under-utilized fields. Maybe this is possible by finding out if a field has not been updated since long time, by looking up in change history of only in those issues where intended field is not empty ?
Or maybe there's any other ways ?

Any possibilities/ideas much appreciated.

Thanks much

3 answers

0 votes
Lokesh
Contributor
September 28, 2021

Able to get something working for a field as follows

{code}

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.web.bean.PagerFilter
import java.time.ZoneOffset

def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

//get recent issues in reverse order of creation
def jql = /project = 'ProjectA' and 'Field1' is not EMPTY order by Created desc/
def parseResult = searchService.parseQuery(currentUser, jql)

assert parseResult.isValid(): "The following JQL was not valid: $jql"

def results = searchService.search(currentUser, parseResult.query, PagerFilter.unlimitedFilter)
def latestIssue = results.getResults().head()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(latestIssue, 'Field1')

if (changeItems?.size() > 0) {
def lastupdated = DateUtils.getDurationString((new Date().getTime() - changeItems.created.head().getTime()) / 1000 as Long)
log.debug(lastupdated)
}

{code}

Where as foll. doesn't, as it is another version with additional one more field, to find out for many fields in same script

{code}

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.web.bean.PagerFilter
import java.time.ZoneOffset

def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

//get recent issues in reverse order of creation
def myFieldList = ['Field1']
for (myFieldName in myFieldList) {
def jql = /project = 'ProjectA' and '$myFieldName' is not EMPTY order by Created desc/

def parseResult = searchService.parseQuery(currentUser, jql)

assert parseResult.isValid(): "The following JQL was not valid: $jql"

def results = searchService.search(currentUser, parseResult.query, PagerFilter.unlimitedFilter)
def latestIssue = results.getResults().head()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(latestIssue, '$myFieldName')

if (changeItems?.size() > 0) {
def lastupdated = DateUtils.getDurationString((new Date().getTime() - changeItems.created.head().getTime()) / 1000 as Long)
log.debug(lastupdated)
}

{code}

Comparison as followsScreenshot 2021-09-28 191403.jpg

Not sure why it doesn't seem to return anything.

Any clue, much appreciated

Thanks.

0 votes
Nic Brough -Adaptavist-
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.
September 18, 2021

For volume of fields used, you can run JQL such as "<field> is not empty" - if it returns 3, you can say people aren't using the field much, if it returns 30,000, you know they are!

If you do get a large result, it might also be worth looking at the actual usage - if it's a select list, you'll probably want to consider a field unused if every usage of it is the same.  And then there's people who've done silly things like default text in text fields so 99% of your issues have a description filled with a default.

Recently updated is a bit more difficult, but @Ismael Jimoh  covered it (changeitem and changegroup are the right names!)

0 votes
Ismael Jimoh
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.
September 17, 2021

You can narrow this down also with a JQL search of custom field is not empty AnD updated within specific date Order By updated.
Though this doesn’t give you exactly what you want, you still get all issues which match your preferences and it lets you see if the field has been updated recently via issue history.

For something more concrete you need to dig this from your database as you rightly mentioned. Check the changegroup and changeitem tables(please double check the names again as they may not be 100% correct).

Regards.

Suggest an answer

Log in or Sign up to answer