I am trying to implement a scripted field which will take very long html links from one custom field and display it as a short link in another custom field.
So, there are two fields:
CF1) SBM URL Link - custom field type URL Field, where I will store long URL links
CF2) SBM URL - scripted field which I am trying to configure to display only Lind to SBM
I thought that to display a string as HTML you need to select the Template HTML, which I did
This is the scripted field code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField link_url = customFieldManager.getCustomFieldObjectByName("SBM URL Link")
def link_str = (String) issue.getCustomFieldValue(link_url)
if (link_str)
{
return '<a href="' + link_str + '">' + 'Link to SBM' + '</a>'
}
return null
As a result, I get a string not a HTML link.
How can I make it work?
A colleague of mine helped me to solve this one. I was very close anyway.
I should have used normal < > characters.
The proper code is below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField link_url = customFieldManager.getCustomFieldObjectByName("SBM URL Link")
def link_str = (String) issue.getCustomFieldValue(link_url)
if (link_str)
{
//this line was incorrect in the previous code
return '<a href="' + link_str + '">' + 'Link to SBM' + '</a>'
}
return null
Thanks @Volodymyr Havryliuk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.