Calculation fields and transitions

Hello,

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

0 vote
Vasiliy Zverev Community Champion Dec 14, 2015

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);
lastFriday.set(Calendar.HOUR,11);
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());
            break;
        }
}

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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 39m ago in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

37 views 3 3
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