Need help in scripting a custom field

Basically I have created a scripted field with "Free text searcher". When ever I create new issues, Jira needs to validate the issue key entered in this field and link that issue with the newly created one. Also the issue link type should be "relates to". Can any one provide the script for this as I am very new to groovy.

2 answers

1 accepted

This widget could not be displayed.
This widget could not be displayed.

Doesn't sound like a scripted field... they are just used for derived values and are read-only.

I think you just want a short text field, and do the linking in a post-function. But why don't you use the put the issue links system field on the screen? You can do that in recent versions...

Jamie,

Thanks for your input. Kindly find my update pasted below.

1. Using system field Issue link will not work as user want the field to be named "Parent ticket".

2. I tried your suggestion of creating a simple text field and added a script to post function for linking. However this script does not create a link nor logs errors. Let me know you if any modification needs to be done on this script.

################

def ComponentManager componentManager = ComponentManager.getInstance();

def customFieldManager = componentManager.getCustomFieldManager();

def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_21541');

def parentTaskID = issue.getCustomFieldValue(parentTaskIDCF);

if (parentTaskID == null || parentTaskID == '') {

return true;

} else {

def issueManager = ComponentAccessor.getIssueManager();

def parentIssue = issueManager.getIssueObject(parentTaskID);

def isParentIssueValid = parentIssue != null &&

parentIssue.projectObject.key == issue.projectObject.key ;

if (isParentIssueValid) {

def issueLinkManager = ComponentAccessor.getIssueLinkManager();

def issueLinkTypeManager = componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class);

def issueLinkType = issueLinkTypeManager.getIssueLinkTypesByName('Relates To').get(0);

def authenticationContext = componentManager.getComponentInstanceOfType(JiraAuthenticationContext.class);

issueLinkManager.createIssueLink(issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.user);

#######################
Appreciate your help and thanks in advance.

you need to add some logging... it looks OK, but it should either create the link or throw an error.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

79 views 1 0
Join discussion

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