Not able to get last custom field value using getChangeItemsForField getFrom()

Rob_Duncan July 27, 2018

I am trying to see the last value for a specific custom field with the code below but I m getting an error.  Could someone advise how to resolve this?

 

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;

//For test
Issue issue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase("EPIC-10");
String fieldName = 'Who'

def ChangeHistoryManager= ComponentAccessor.getChangeHistoryManager();

List<ChangeItemBean> changeItems
changeItems = ChangeHistoryManager.getChangeItemsForField(issue, fieldName)
if (changeItems.size()>0) {
return changeItems.get(0).getFrom()

}

 

2 answers

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
July 27, 2018

Hello,

What is the error?

Rob_Duncan July 27, 2018

Hi @Alexey Matveev, the following:

screenshot.png

Alexey Matveev
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.
July 27, 2018

It is a static compilation error. Just run this script. It should work.

Rob_Duncan July 27, 2018

@Alexey Matveev, thank you.  It is returning null despite size returning 2 with the expected value in getCreated(), but I can't seem to get the value of the From or To string... 

 

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;

//For test
Issue issue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase("EPIC-10");
String fieldName = 'Who'

def ChangeHistoryManager= ComponentAccessor.getChangeHistoryManager();

List<ChangeItemBean> changeItems
changeItems = ChangeHistoryManager.getChangeItemsForField(issue, fieldName)
if (changeItems.size()>0) {
return changeItems.get(changeItems.size()-1).getFrom()

}
Alexey Matveev
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.
July 27, 2018

Try like this:

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;

//For test
Issue issue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase("EPIC-10");
String fieldName = 'Who'

def ChangeHistoryManager= ComponentAccessor.getChangeHistoryManager();

List<ChangeItemBean> changeItems
changeItems = ChangeHistoryManager.getChangeItemsForField(issue, fieldName)
if (changeItems.size()>0) {
return changeItems.get(changeItems.size()-1).getFromString()

}
Rob_Duncan July 30, 2018

@Alexey Matveev, spot on - thank you!

Alexey Matveev
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.
July 30, 2018

If my answer helped you, kindly mark it as accepted. In this case other users with a similar question will be able to find this answer.

0 votes
Rob_Duncan July 27, 2018

screenshot.png

Alexey Matveev
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.
July 27, 2018

Hello,

It is a static compilation error. Just run this script. It should work.

Suggest an answer

Log in or Sign up to answer