Forums

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

How do I Extract Story Points from ChangeHistoryItem (Object in Java API)

Avi Bachar
Contributor
October 17, 2021

I am working on analysis of Change Log of an Issues 

and I got  into a problem.

when I try to get the From or To of Story Points log item, I am getting null.\

Why is that? and How I overcome this problem?

 

I have this function utility I wrote to DEBUG the issue (narrow the problem)

and it is the only thing I am running

 

// The Main Code
// Quite Simple - Call the utility change_log_print_field 

change_log_print_field (issue,"Story Points")
return

// end of Main code


// the utility
// its purpose is to print all the log history of a selected field to logger
// in this case of Story Points

int change_log_print_field (Issue current_issue,String field_name){

def HistoryOfCurrentIssue = ComponentAccessor.getChangeHistoryManager().getAllChangeItems(current_issue)
ChangeHistoryItem caught_change = null
int count = 0

for (change in HistoryOfCurrentIssue ) {

if(change.getField().toString().indexOf(field_name)>-1 )
{
count = count + 1
log.warn "change_log_print_field: Date:"+change.created+"// Field:"+change.getField()+"// Froms:"+change.getFroms()+"// Tos:"+change.getTos()+"// User"+change.getUserKey()

}

}

return count

}

 

This is a picture of a single Issue I tested from Jira issue History

 

image.png

as you can see there are values in to and froms

but in the logger this is what I get

image.png

a more focused pic of the logger

image.png

in the code, this is the class I am using to access the History Log

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/changehistory/ChangeHistoryItem.html

works fine for text but not for Story Points

Any Suggestion?

Other ways to Access History Log that works are welcome as well.

1 answer

1 accepted

0 votes
Answer accepted
Suvarna Gaikwad
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.
October 18, 2021

@Avi Bachar This should work. Please try and let us know.

int change_log_print_field (Issue current_issue,String field_name){

List<ChangeItemBean> allitems = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, field_name);
def size = allitems.size();
if(size >=1){
for (int i = 0; i < size; i++){
ChangeItemBean x = allitems.get(i);


def oldValue = x.getFrom();
def newValue = x.getTo();
def timecreated = x.getCreated();

log.warn "Field " + field_name + " changed from " + oldValue + " to " + newValue + " on " + timecreated
}

}

return size;
}

Avi Bachar
Contributor
October 19, 2021

Thanks 

This actually works 

And I am using it now 

But it is strange that it doesn't work for

ChangeHistoryItem class

Which should be the preferred way 

To work with history log

Cause it takes in consideration multi value field like sprints 

Which the ChangeItemBean do not

Thanks any way for the solution 


Suggest an answer

Log in or Sign up to answer