Create a pre-filled link type


Our documents are stored in a document management system which can be reached via an html link. Such a link looks like:<NUMBER>

Is is possible to add a link type (like the default 'Jira issue' and 'Web link' to the link screen, in which the user only has to fill in the <NUMBER> and the rest of the URL is added automatically?

How do I do this?


2 answers

0 votes

I'd do this with a derived field (I usually do those with the script runner addon)

If you give the user a text field for them to enter the number on create/edit screens, but then put a derived field in that displays "<basic url>/number", then you're done. I'd probably display it as a full link as well, and this has the advantage that if you move the CMS, you only need to tweak the script to update all your issues.

@NicThanks for your reply. But that is a bit rudimentary, since there is an excellent out-of-the-box screen which contains (currently) two options. I would think it should be possible to put in another. After all the 'Jira issue' option is specific kind of web link.

Solves the problem with minimal complexity.

You could do something more advanced of course. Your users could simply use the links too, but it sounds like you want to be a bit more clever.

You could also take the same starting point as I suggested - a simple field with just the number to be entered. Then write a listener that converts it into a web-link when people update the issue...

Well NicI've been trying to get it to work, but it keeps giving me errors, about the user (especially this part getRemoteIssueLinkByGlobalId(user, missue, globalId); ) 

javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'arholtkam:1' with class 'com.atlassian.jira.user.BridgedDirectoryUser' to class 'com.atlassian.jira.user.ApplicationUser'

So basically I can't get it to work. I'm not a Java/Groovy developer, so I'm just hacking around.

What I want is to use two fields to create a link. One field is the document number and the other one the type of document. Together they give me enough info to create the link.

Hope anyone can help me.


import com.atlassian.jira.component.ComponentAccessor;
//import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.BridgedDirectoryUser;
MutableIssue missue = issue;
//JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
//User user = authContext.getLoggedInUser();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();
CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField cfTCEDoc = cfManager.getCustomFieldObjectByName("Add TCE document");
CustomField cfTCEDocType = cfManager.getCustomFieldObjectByName("TCE document type");
//Get document number
def TCEDoc = issue.getCustomFieldValue(cfTCEDoc);
//Get document type
def TCEDocType = issue.getCustomFieldValue(cfTCEDocType);
//check if 'Add TCE document' value is set
if (TCEDoc == null) {return "NOK";}
//Check if type is specified
if (TCEDocType == "None") {return "NOK";}
//Create global id
def globalId = issue.getKey() + "-" + TCEDoc;
//First get a list of issue links to check if the link already exists
RemoteIssueLink existingLink = getRemoteIssueLinkByGlobalId(user, missue, globalId);
if (existingLink == null) {
//The link does not exist yet

RemoteIssueLinkBuilder remoteIssueLinkBuilder = new RemoteIssueLinkBuilder();
def url = "http://tce/tc/webclient?argument=" + TCEDoc;
RemoteIssueLink remoteIssueLink =;
RemoteIssueLinkService remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class);
RemoteIssueLinkService.CreateValidationResult createValidationResult = remoteIssueLinkService.validateCreate(user, remoteIssueLink);
if (remoteIssueLinkService.create(user, createValidationResult) == null) {
// set custom field 'Add TCE document' to "" now the link has been created
TCEDoc1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(TCEDoc1), ""),new DefaultIssueChangeHolder());
return "Link not created";

} else {
// set custom field 'Add TCE document' to "" now the link creation has failed
TCEDoc1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(TCEDoc1), ""),new DefaultIssueChangeHolder());
return "Ok";
} else {
// set custom field 'Add TCE document' to "" the link already exists 
TCEDoc1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(TCEDoc1), ""),new DefaultIssueChangeHolder());
// set custom field 'TCE document type' to "" the link already exists 
TCEDoc2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(TCEDoc2), ""),new DefaultIssueChangeHolder());
return "NOK"

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,000 views 4 9
Read article

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