Time custom field question

Hi All,

I created a scripted field which results the time in a particular status for each issue.

The endusers will export the report to excel which contains this custom field value. The problem is that this field - according to the time spent in that status - contains '2d 1h' or '3w 4d 4m' values and they need every value only in minutes because of the excel.

How can we do that?

Thanks in advance!

Rumi

2 answers

1 accepted

You need to specify a separate template for the excel view in your atlassian-plugin.xml and use it to format the time in minutes only.

<resource type="velocity" name="excel" location="mytemplate.vm"/>

Hi,

the excel export will be generated from Issue Navigator. Can I implement this script to a scripted field?

The excel view will be used whenever you custom field will be used in an "export to excel" action regardless of what/where it was triggered from.

I'm not sure I understand what you mean by scripted field. I thought you meant you wrote the plugin for the custom field yourself, in which case the above solution is correct. However, if you use a third party plugin you need to clarify this with the developer.

ok,

sorry:)

the current custom field which results the time spent in the particular status is a scripted field I made.

The field will be displayed in the issue navigator and the results (about 300 issues) will be exported to excel.
The users who need these custom field ask for displaying these time values in 'Minutes' in order to easily compare in the excel report.
So I think there is nothing to do with excel: can the script be altered to display the time spent in minutes?

here is the code:

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
 
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
 
def inProgressName = "Clarification"
 
def rt = [0]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->
 
    def timeDiff = System.currentTimeMillis() - item.created.getTime()
    if (item.fromString == inProgressName) {
        rt << -timeDiff
    }
    if (item.toString == inProgressName){
        rt << timeDiff
    }
}
 
// NOTE: doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(rt.sum() / 1000))

Oh, the Scripted Field from the groovy plugin(?). Then you have no option but to always return the time in minutes.

I'm not quite sure that's the case. You can use a custom template, and in that you can tell whether it's being rendered for excel or not, and do the conversion to pretty as necessary. Don't have a fully worked example though/

Hi Florin,

yes, this is a groovy script which works great. The only wish is to show the time spent value in minutes. But I'm out of idea...:(

Just replace

DateUtils.getDurationString(Math.round(rt.sum() / 1000))

with

Math.round(rt.sum() / 60000)

Hi Florin,

I get result but also a warning message after the code replace:

"The indexer for this field expects a java.lang.String but the script returned a java.lang.Long - this will cause problems."

Replace with

new String(Math.round(rt.sum() / 60000))

Hi Florin,

I insterted:

new String(Math.round(rt.sum() / 60000))

and it resulted:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script21.groovy: 23: unable to resolve class string @ line 23, column 1. new string(Math.round(rt.sum() / 60000)) ^ 1 error A stacktrace has been logged.

You did "new string", not "new String". See the error message.

OK, use:

Math.round(rt.sum() / 60000).toString()

You1re right, I corrected but it didn't work as well:

javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.lang.String(java.lang.Long) A stacktrace has been logged.

Perfect!

thank you

Sleep well Jamie

Where you render field representaion? In script or in velocity template? If in template, you need separate template for excel export

Hi,

the excwel export will be generated from the Issue Navigator.

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 Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

84 views 0 5
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