Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner Scripted Field rendering string not HTML Link

Bogdan Gorka
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2020

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

temp2.png

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. 

temp.png

How can I make it work?

1 answer

1 accepted

0 votes
Answer accepted
Bogdan Gorka
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2020

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 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.2.3
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events