Add dynamic link based on other field value

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

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.

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?!

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 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 ...

3,313 views 14 20
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