Forums

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

Get timeStamp of fixVersion custom field

aviv_eldad
Contributor
October 30, 2022

Hello everyone!

I am new in Jira and groovy, and I need your help.

I want to get the time stamp of fixVersion field, if it is possible. The idea is to get all the stories and tasks where the fix version field was updated in the last 30 hours. I don't know if I'm right, and maybe my algorithm can be improved (maybe the JQL can be written differently?)

This is what I've got so far(not much):

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

 

 

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

 


def query = jqlQueryParser.parseQuery('project in (My_Project, Proj) AND issuetype in (Story, Task) AND updated >= -30h ')
def results = searchService .search(user,query, PagerFilter.getUnlimitedFilter())
results.getResults().each {documentIssue ->
//ver is array of fix versions
def ver = documentIssue.getFixVersions()
if(!ver.isEmpty()){

     //do something
}


}

 

I've searched on the internet and couldn't find anything. I will really appreciate your help, thank you!

1 answer

1 accepted

1 vote
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2022

Hi @aviv_eldad 

Welcome to the Community!

Your starting point is correct, there is no way to get an updated date/time for a specific field out-of-the-box in Jira. So, fetching the issues which were updated within the last 30 hours and then traversing their histories if the fix version field was updated within 30 hours makes sense.

Here is how you can fetch all changes in Fix Version field for an issue

List<ChangeItemBean> changeItems = changeHistoryManager.getChangeItemsForField(issue, Fix Version"));
then you will need to check the date/time to be within the last 30h.
However, this is not a performance friendly solution. You will need to fetch thousands of issues and check their histories, and it might have a performance impact on your Jira instance.
I'd strongly recommend using Enhancer Plugin's  Field Change Date Custom Field which you can use directly in your JQL function:
'project in (My_Project, Proj) AND issuetype in (Story, Task) AND cf_fv_updated >= -30h '

assuming cf_fv_updated is the new custom field name which will hold the date/time value when an issue's fix version field is updated.

I hope it helps!

Tuncay

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2022

btw, I may be biased as I am one of the folks behind Enhancer Plugin. Please let me know if you need further assistance on both solutions.

aviv_eldad
Contributor
November 1, 2022

Thank you @Tuncay Senturk so much! I'll look into it

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 2, 2022

You're welcome!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events