Convert String to URL in vm file.

Hi All,

I want to convert a plain String to a URL(clickable link) in a vm file. I have tried using $link.encode(String) but it takes as a literal. That is , it just prints "$link.encode(String)", doesnt encode. I am not sure what do I have to enable and where in jira. Please suggest. We are using jira 6.0.8 currently which will be upgraded shortly to the latest version.

Thanks,

Hemanth

1 answer

Hi! :)

Have you tried this one:

ib.name

Escapes the characters in a String to be suitable to use as an HTTP parameter value.

String url(Object string)
<dl><dt>Parameters</dt><dd><dl><dt>string</dt><dd>the string to escape values, may be null.</dd></dl></dd></dl><dl><dt>Returns</dt><dd>a new escaped String, null if null string input</dd></dl>

Delegates the process to java.net.URLEncoder#encodeURL(String,"UTF-8").

If $url had the following value:

Hello here & there

then the following Velocity script:

$esc.url($url)

produces this output:

hello+here+%26+there

Source: http://velocity.apache.org/tools/devel/generic/EscapeTool.html#url()

The other option would be ( https://velocity.apache.org/tools/devel/velocity-tools-generic/apidocs/org/apache/velocity/tools/ConversionUtils.html#toURL(java.lang.String) ):

toURL

public static URL toURL(String value)
<dl><dd>Converts a string to a URL. It will first try to treat the string as a File name, then a classpath resource, then finally as a literal URL. If none of these work, then this will return null.

</dd><dd><dl><dt>Parameters:</dt><dd>value - - the string to parse</dd><dt>Returns:</dt><dd>the URL form of the string or null</dd><dt>See Also:</dt><dd>File, ClassUtils.getResource(String,Object), URL</dd><dd></dd><dd></dd></dl></dd></dl>

I'm trying the following in a macro:

$esc.url($url)

However, I just see the same output: $esc.url($url)

Any assistance would be appreciated

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,755 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot