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

This widget could not be displayed.
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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 12 hours ago in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

60 views 0 8
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