I want to have a custom template in a script field which does some calculation. Basically the script outputs the $value in seconds and I'm able to use the form "$getPrettyDuration.call($value)" (as found in the documentation). But I'd like to convert the seconds into hours, but not changing $value from seconds into hour, just for displaying.
Is there a reference what can be done in this "Custom Template" field? Is this just Groovy script? Is there more documentation available for this field?
The templates are for telling JIRA how to handle the data that is in them. They're not for doing the formatting of the output.
Your scripted field should be outputting $value in the format you want to see it, not trying to format it on the way out. If you really do need the $value in seconds as well, you'll want a separate field to do that, as the content of the field is different.
Not sure about that, the example in the ScriptRunner documentation (https://scriptrunner.adaptavist.com/latest/jira/recipes/scriptfields/workRemainingInLinkedIssues.html) also does this using
$getPrettyDuration.call($value)
When saving it as a number instead of free text I think indexing of the field makes more sense, also when using this field in searches for sorting it's easier when it's saved as number. Or am I wrong here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it outputs the value that is desired.
You're right about sorting, you want numeric for that. The problem here is that you're asking for two values to come out of one thing. For that to work, you need code inside jira to do it - your script could, in theory, output both, but JIRA would need to understand "show value 1, while search/sorting on value 2". The original estimate field is built that way, but ScriptRunner only has templates for single value outputs - text OR numbers OR dates etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That said, might be worth asking Adaptavist to add a new template for "length of time" - store seconds, display pretty. I will poke the team and see if we've already got an issue raised for it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic for clarification. The idea with the two values won't be too bad. But what's against doing it like the function getPrettyDuration
? Something like an output formater? Are there any other functions available like getPrettyDuration
?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's nothing against using the pretty duration thing, it works fine. The problem is that you're trying to work with two values in one field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't really need two values. Let me rephrase my original question:
The getPrettyDuration
is not configurable (afaik), that means it always outputs it in the "pretty" format designed by Atlassian, which isn't what I want. All I want is to just convert the seconds stored in the index in hours for display purposes.
One questions stays: What functions are available for Custom Templates, besides the getPrettyDuration
? Is there anywhere a documentation available?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then you build a custom field that has an output of <value field>/3600 (maybe with some rounding)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, that would make it... So do I understand this correctly that there are no more functions available for Custom Templates than getPrettyDuration
?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes
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.
I'll take a risk here and disagree with Nic.
Templates are precisely for formatting the value returned by the script field code for display to use the user.
You can convert to hours using code as shown below.
Caution: You must use the number range indexer for the field, otherwise ScriptRunner will convert the return value to whatever is suitable for the chosen indexer.
image2016-8-30 10:30:50.png
(for detail see https://answers.atlassian.com/download/attachments/40348731/image2016-8-30%2010%3A30%3A50.png?version=1&modificationDate=1472549439634&api=v2)
> Ok, that would make it... So do I understand this correctly that there are no more functions available for Custom Templates than getPrettyDuration
There is a bunch of other stuff available although not well documented.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is a bunch of other stuff available although not well documented.
II have the same question as Tobias. Is there any documentation for what methods are available for custom templates? I've been scouring the internet to no avail,
Methods look to be formatted as Velocity templates but I can't find documentation anywhere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, they are velocity templates. I tried to answer your question here: https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html#comment-2928282368
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.