Add dynamic link based on other field value

Felix Lepa May 14, 2014

We need to provide links to a different system based on the value of a field on each issue. The particular use case is to link the atlassian jira issues to work items in our TFS repository.

I want to be able to have a link on each issues that concatenates our tfs url (ex https://tfshost/tfs?id=) and the value of the TFS Work Item field (ex 123) so that the end result is a clickable link that sends the user to http://tfshost/tfs?id=123.

Any ideas?

2 answers

1 accepted

1 vote
Answer accepted
BenjiI
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.
May 14, 2014

Hi Felix,

I hate to say it every time, but unfortunately I am afraid this type of customizations are to advanced for a jira ondemand instance. You need at least jira downloaded so you can install plugins like Scriptrunner or upload your own plugins with custom functionality.

BenjiI
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.
May 15, 2014

Hi Felix,

Although the solution cannot be implemented in JIRA on-demand, I think it is still interesting to share my solution:

1) Install the Scriptrunner plugin

2) Create a custom field named "TFS Work Item" of type Text Field (or any type you want)

3) Create a custom field named "TFS Url" of type Scripted Field (Installed by the scriptrunner plugin)

4) Goto Admin > Addons > Scripted Fields and locate your scripted custom field. Next click the Edit link to open edit mode. In the script field paste the following code:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue; 
 
 
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager(); 
CustomField tfsCustomField = customFieldManager.getCustomFieldObjectByName( "TFS Work Item" ); 

String url = "http://tfshost/tfs?id=" + issue.getCustomFieldValue(tfsCustomField);

return "<a href=\"" + url + "\">" + url + "</a>";

and make sure the HTML template is selected. This renders the value returned by the script as HTML (in this case a hyperlink).

5) Add the TFS Url to all the screens were it should be visible

This will be the result:

The advantage of using the Scriptrunner plugin is that the scripted field will be updated automatically whenever an issue field is updated. Changing the TFS Work Item field also updates the url.

This script does not check for null-values, but that test can be easily added :-)

Hope this helps?!

William JUTEAU January 29, 2021

Hi Benji,

How do you do the "and make sure the HTML template is selected. This renders the value returned by the script as HTML (in this case a hyperlink)."

In my Field configuration, I don't have the Renderers option on the scripted field just like some other fields...

Thanks

0 votes
Deleted user February 8, 2017

If someone would like to use Benjis code on JIRA 7, you have to modify it as shown below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField tfsCustomField = customFieldManager.getCustomFieldObjectByName( "TFS Work Item" );

String url = "http://tfshost/tfs?id=" + issue.getCustomFieldValue(tfsCustomField);

return "<a href=\"" + url + "\">" + url + "</a>";

#ComponentAccessor

best regards,
Anton 

Suggest an answer

Log in or Sign up to answer