How to compare description field to string multi-lines using velocity?

I would like to set a description template for only one JIRA project (create issue).

To make it flexible I would like the description to toggle between empty "" or the template such as:



On several lines

depending on which JIRA project is selected at create issue or do nothing if the description contains something else already.

I tried to update the following velocity file:


with this very simple code before rendering the field:

#set ($template = "Put


#if ($issue.project.key && $issue.project.key == "TTT")
  #if ($description == "")
    #set ($description = $template)
#elseif ($description == $template)
    #set ($description = "")
## let the renderer display the edit component

But if the project is not TTT, even if the description matches the template, the string comparison does not return true. Please note it returns true if the template contains only "One line:".

I'm running with JIRA 6.1. Can anyone help me?

PS: I also tried a javascript but it fails to execute in every situation.
At least the velocity script fires in every situation but the comparison fails.

1 answer

I think I found a solution. I need further testing to prove it functions well.

I discovered that Velocity can use other java libraries: Example from the engine (or user guide) Click on Javadoc > then on org.apache.velocity.util > then on StringUtils > collapseNewlines().

Note: These links points to the last API under development. Not sure which version Atlassian is using: please start clicking from the correct engine version 1.7, 1.6, or even 1.5.

As the string comparison functions between 2 single line variables we could create temporary variables and compare them instead.

#set ($stringtemplate = $template.collapseNewlines())
#set ($stringdescription = $description.collapseNewlines())

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
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
Join discussion

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