Custom field text to clickable URL. Edited


I have a requirement as following

The user will enter a number in the custom field which is validated to enter number only while creating a ticket. Once ticket gets created I need that number to get added to the URL so that user clicks that link and it takes to the appropriate page. 

Eg: In a different enterprise system, there is a numeric id for a ticket, and that numeric id is entered in Jira, I need JIRA custom field which enables users to input that number and that field data should convert into URL like in ticket view  so that user gets direct to that page when clicked.

Am new to JIRA scripting and am not sure where to add the script and what to code. I'm a beginner so any help is appreciated


Thank you

1 answer

1 accepted

As I think you have already worked out, I would probably want to do this as a "scripted field" in ScriptRunner.

There's quite a lot to do here for a first-time user, so I will try to be brief, and expect questions if I am too brief, or assume things you don't know!

  • Add a new custom field
    • Type: numeric
    • Name: Let's call it "Reference entry"
    • Place it on create and edit screens.  You might find it useful on view, but I'm not sure.
  • Add a second custom field
    • Type: Scripted field
    • Name: Let's say "Reference url"
    • Place it on the view screen.  (It won't show on create/edit if you add it, but don't worry if you do)
  • Now, go to Admin -> ScriptRunner -> Scripted fields
  • You will find a field in there called "Reference url"
    • Set it up to have an output type of "html"
    • Give it the following script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObjectByName("Reference entry")
def theId = (String) issue.getCustomFieldValue(customField)

if (theId)
   return '<a href="' + theId + '>See item ' + theId + '</a>'

return null


Thank you for the answer.I have couple questions, here it goes


In the line

def theId = (String) issue.getCustomFieldValue(customField), I think I should use custom field number of(reference URL) there in order to pull the data, am I correct? or field being scripted field it automatically pulls data?

and what is See item in return statement? maybe a dumb question but trying to understand the code.

A scripted field is aware of the issue it is running for.  You don't need to think about it, you can just use the issue object like my code does.

The customField is worked out by the line above it in the script.

The "see item" is some text I added as an anchor for the url field, so you see something like "See item: 12345" instead of - totally optional and cosmetic.

ah. understood.


Thank you

Suggest an answer

Log in or Join to answer
Community showcase
Pedro Felgueiras
Asked 38m ago in Jira

Clone a Zephyr issue

When I try to clone a Zephyr issue only a popup showing the issue id and nothing more shows.  On the browser console I see:  RTE not registered Error: No jira/editor/registry at c...

9 views 0 0
View question

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