How to create custom field with URL prefix string?

Alexander Kaptsanov November 16, 2015

I would like to add a custom field named "Case" that will be a hyperlink

as follow "Case" <number> as http://mwz/<case Number>

the user will be able to add only case number 
the field will be http://mwz/ + <case Number> 
like 
(System prompt -->)Case:       680103097 (<-- user input)

The user should not be able even accidentally to change the prefix(i.e. http://mwz/).

and will be shown as

Case: http://mwz/680103097           in any JIRA screen

4 answers

1 vote
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2015

Hi Alexander,

I have posted below a code example which shows how you could use a scripted field provided by the Script Runner plugin to take the Case Number out of a number field which stores the Case Number and the to display it in a scripted field called Case which displays the URL. You could always make the Case Number field mandatory which would then mean that you would not need the else clause in the code below.

When setting up the scripted field the must be set to 'HTML' in order to make the returned hyperlink clickable.

// Get the Case Number
def caseNumber = getCustomFieldValue("Case Number") 

// Check if  a case number exists and if so construct and set the Case URL
if (caseNumber != null){
def baseURL ="http://mwz/"
// Construct the HTML hyperlink tag to be returned.
def caseURL = "&lt;a href=" + baseURL + caseNumber.toLong() +"&gt;" + baseURL + caseNumber.toLong() + "&lt;/a&gt;"
    return caseURL
// If no case number exists return a warning message. 
}else{
    return "No current case exits"
}

 

I hope this helps.

 

Many Thanks

Kristian

0 votes
Karen Clark January 13, 2016

It's kind of strange that Atlassian never implemented this as an out-of-the-box feature. I've had use cases that would benefit from this since 2005... sad

0 votes
JamieA
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.
November 16, 2015

I would use a simple scripted validator from Script Runner with a regular expression:

cfValues["Case"] ==~ "http://mwz/[\d+]"

(untested)

Alexander Kaptsanov November 17, 2015

Hi Jamie, I do not have experience in this field. The idea is very attractive. I would be very grateful for a detailed step-by-step guide or any links to similar subject. Thanks, Alex

0 votes
Mario Günter
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.
November 16, 2015

Hi Alexander, 

you could defina a custom field of type "URL".

There you can set a default value, e.g. http://mwz/xxx"

Your users will only have to replace xxx with a number.

In the custom field configuration you can define a default value, here "Standardwert bearbeiten":

2015-11-16 16_33_40-Benutzerdefiniertes Feld konfigurieren_ URL.png

How to create custom fields, please refer here: documentation

Hope this helps.

Cheers, 
Mario 

 

Suggest an answer

Log in or Sign up to answer