I have a request to create some scripted fields to track time in status. I've created all of the scripts and placed them on a new tab in the View screen. I've created the 4 fields all of Duration Searcher type via the Script Runner Scripted Fields add on and changed the context to the correct project
I have two screen schemes: one for Bugs and one for all other issue types (Epic, Improvement, Story, Task, New Feature, Sub-task).
The scripts work as expected, however, the placement of the fields when in task view changes.
If nothing is in the TimeTracking, Agile or Additional Info tabs then the fields display in the Details section.
If I have data entered on one of the other tabs of the screen the 'Duration' fields display on the Duration tab I've created for them.
However, the above isn't always consistent however, sometimes the fields display in the dates section. This is random behavior that I cannot figure out.
I understand some of this behavior since these are non-editable fields however, is there any way that the fields can always be displayed in the Duration tab instead of switching places? Or would it be possible to always display them in the Dates section instead of a screen tab (maybe a change in template could accomplish that)? I think I would prefer them to always be in the Dates section if possible.
Thanks in advance!
Avril
Hi Avril,
Is it possible to attach a screenshot of your Scripted Fields configuration ?
Regards, Thanos
Hi Thanos,
Sure. The script for the initial status, Backlog, is set up slightly differently than the other three fields but each field has a context for the specific project for all issue types, the Searcher Template is Duration and type of each field is a Scripted field.
Backlog config:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.Issue;
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def statusName = "Backlog"
def createdDateDiff = System.currentTimeMillis() - issue.getCreated().getTime()
List<Long> rt = [0L]
rt << createdDateDiff
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item -> item.fromString
// Get the time passed since status change
def timeDiff = System.currentTimeMillis() - item.created.getTime()
// If the status change left our status, we want to subtract the time passed since then
if (item.fromString == statusName) {
rt << -timeDiff
}
// If the status change goes to our status, we want to add the time passed since then
if (item.toString == statusName){
rt << timeDiff
}
}
def total = (rt.sum() as Long) / 1000
return Math.round(total) ?: 0
The other three fields have the exact same code and set up with exception of field names:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def inProgressName = "In Progress"
def reopenedName = "Reopened"
def openName = "Open"
List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}
def total = rt.sum() as Long
return (total / 1000) as long ?: 0L
Please let me know what other information I can provide.
Thank you,
Avril
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.