Hi
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 http://abcdef.com/nbvj/1234 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
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!
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="http://abcdef.com/nbvj/' + 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 http://abcdef.com/nbvj/12345 - totally optional and cosmetic.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your quotation marks are wrong, it shoul be something like that:
return '<a href=http://abcdef.com/nbvj/'+ theId +'>'+"Seeitem:"+theId +'</a>'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same exact scenario to be achieved in JIRA cloud. Could you please guide me in providing the script for scripted field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Should be able to use https://library.adaptavist.com/entity/calculate-custom-field-on-issue-update?tab=cloud to set a field for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.