Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted fields change location while in View

Avril Bower
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 24, 2018

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). 

View_Screen_Duration_tab.png

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.Duration_in_Details.png

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. 

duration_on_duration_tab.png

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.

druation_in_Dates.png

 

 

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 

1 answer

0 votes
Thanos Batagiannis [Adaptavist]
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.
May 25, 2018

Hi Avril, 

Is it possible to attach a screenshot of your Scripted Fields configuration ?

Regards, Thanos

Avril Bower
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 29, 2018

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. 

duration_fields.png

Backlog config: 

duration_fields_Backlog.png

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: 

duration_fields_Inprogress_Open_Reopen.png

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

Suggest an answer

Log in or Sign up to answer