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

This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

85 views 1 0
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