Calculation fields and transitions

Asti Messer December 14, 2015

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 votes
Vasiliy Zverev
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.
December 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
TAGS
AUG Leaders

Atlassian Community Events