Forums

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

How to check custom field history for more than two issues, with the help of Scriptrunner

Durgesh Masurkar
Contributor
September 20, 2023

I have one custom field named "Data", and the values are acb1, abc2, and abc3. This field is editable on the Edit screen.

Requriment- I want to check how many issues(issue count- more than 100) have been moved from abc1 to acb2 or abc3, and how many issues have moved from abc2 to abc3 from 1st June to the current date. With the help of Scriptrunner.

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 21, 2023

Hi @Durgesh Masurkar

For your requirement you can try something like this:-

import com.adaptavist.hapi.jira.projects.Projects
import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def issueManager = ComponentAccessor.issueManager
def project = Projects.getByKey('MOCK')
def issues = issueManager.getIssueObjects(issueManager.getIssueIdsForProject(project.id))
def mailTypeName = 'Mail Type'
def resultMap = [:] as Map<String,Long>

issues.each {
def changeHistories = changeHistoryManager.getChangeHistories(it)
def changeOptions = []

changeHistories.collect { changeHistory ->
def result = changeHistory.changeItemBeans.find {
it.field == mailTypeName
}
if (result && result['toString']) {
changeOptions << result['toString'].toString()
}
}
if (changeOptions.size() >= 3) {
resultMap.put(it.key, changeOptions.size() as Long)
}
}

log.warn "=======>>>Total issue changed: ${resultMap.size()}"

Please note the sample working code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.

Below is a screenshot of the configuration:-

console_example.png

I hope this helps to solve your question. :-)


Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events