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
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"/>
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, the Scripted Field from the groovy plugin(?). Then you have no option but to always return the time in minutes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just replace
DateUtils.getDurationString(Math.round(rt.
sum
() / 1000))
with
Math.round(rt.
sum
() / 60000)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Replace with
new String(Math.round(rt.
sum
() / 60000))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You did "new string", not "new String". See the error message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, use:
Math.round(rt.
sum
() / 60000).toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where you render field representaion? In script or in velocity template? If in template, you need separate template for excel export
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.