Calculation fields and transitions


I have installed JIRA Misc Custom field to calculate numbers value from fields and it works properly, however now I need to investigate more the function of this addon.

first question - Is that possible to calculate the time spent from Transition 1 up until we execute to transition 2? If  yes, could you please provide a simple formula for it?

second question - is that possible to calculate gap time within 1 same status. For example after we execute transition 2, it will takes us to Status "Ready for Testing". Is that a way to calculate time from the moment we execute the transition 2 goes to "ready for testing" status until someone create a first comment under that status to indicate acknowledgment of this status.

Many thanks.


1 answer

For this calculations you could try using ScriptRunner (free for JIRA6, need payment for JIRA7).

Here is an example of script to analise change history. It takes an issue status on 11 am of last friday.

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

 * Created by VZverev on 01.12.2015.

Issue issue;

///Начальное значение для статуса
PreviousStatus prevStatus = new PreviousStatus(Calendar.getInstance().getTimeInMillis(), issue.getStatusObject().getName());
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();

//Дата, с которой анализируем историю изменений
Calendar lastFriday = Calendar.getInstance();
lastFriday.add(Calendar.WEEK_OF_YEAR, -1);
lastFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
Date lastFridayDate = new Date(lastFriday.getTimeInMillis())

if(issue.getCreated().getTime() > lastFriday.getTimeInMillis())
    return "новый запрос";

for(ChangeHistory changeHistory: changeHistoryManager.getChangeHistoriesSince(issue, lastFridayDate)) {
    for(ChangeItemBean changeItemBean: changeHistory.getChangeItemBeans())
        if(changeItemBean.getField().equals("status")) {
            prevStatus.setNewStatus(changeItemBean.getCreated().getTime(), changeItemBean.getFromString());

return prevStatus.getStatus().equals(issue.getStatusObject().getName())?"не изменился": prevStatus.getStatus()

class PreviousStatus{
    private long dateInMills;
    private String value;

    public PreviousStatus(long _dateInMills, String _value){
        dateInMills = _dateInMills;
        value = _value;

    public setNewStatus(long _dateInMills, String _value){
        if(_dateInMills < dateInMills){
            dateInMills = _dateInMills;
            value = _value;

    public String getStatus(){return value}

Suggest an answer

Log in or Join to answer
Community showcase
Jason Wong
Published yesterday in Agility Beta

Welcome to agility

Every team in the world is unique, and so   Atlassian believes   that each and every team's best way of working  needs to  be molded to their unique circumstances  – ...

333 views 6 15
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot