Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Problem displaying a custom field type that I created

I have created a new custom field type in my plugin. The new type is designed to contain time duration values similar to those supported by the worklogs (e.g. 3w 2d 1h).

The underlying DB value is store as a Double. The value stored is the number of seconds.

The transport object is a Long (so that it can for example be added to worklog values).

The display object is a String which is generated using a JiraDurationUtils object.

All of this seems to work fine except for one problem:

My velocity template for viewing the value uses $value to display the value on the screen. The value that I am seeing is the number of seconds rather than the formatted string.

My velocity template for editing also uses $value, but when I edit the issue I see the formatted string rather than the number of seconds.

Why do the two templates behave differently and how can I call a function from the view template to convert the value to a formatted string (I already have that function available in my custom field class) ?

I am using JIRA 4.3.3

1 answer

I think you can override the getObjectFromDbValue (or getStringFromSingularObject) method to return the formatted String instead of the long value that is saved.

Another option is ofcourse to put JIRADurationUtils in the context and do the formatting in the view template itself.

I have already overridden getStringFromSingularObject with a version that converts from Long to a formatted String. This is working fine as can be seen when I edit my issue (the value of the custom field appears as a correctly formatted string).

Why is the view template replacing $value with the Long value while the edit template is replacing it with the formatted String (as produced by the getStringFromSingularObject method) ?

I am not at all experienced in using velocity and I don't know how to do any manipulation in the template. What do I need to put in the template (and code ?) to get the following conversion ?


formattedString = durationUtils.getFormattedDuration(longValue, defaultLocale);


Thanks in advance

in the getVelocityParameters method, add JIRADurationUtils to the context. May be the locale too.

params.add("durationUtils", jiraDurationUtils);
params.add("locale", defaultLocale);

You can the do this in template:

#if ($value)
$durationUtils.getFormattedDuration($value, $locale);

Thanks Jobin, that works fine !

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Agile

Join us LIVE: Atlassian & Experts Talk Research & Insights @ Scale

Hello all! What have you learned from your customers lately? Our live-streamed series continues by exploring CX, UX, and the power of research & insights at scale with Leisa Reichelt, Head of R...

249 views 3 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you