How to create custom field with URL prefix string?

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

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

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 

 

0 vote

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

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

(untested)

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

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

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published yesterday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

44 views 0 3
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
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