Creating Issue Link

AKASHB July 21, 2013
Can anybody help me out in creating link between 2 issues using groovy? Its very urgent. I have two issues which are doing handshake i.e there values are selected by using PLugin named Query Custom Issue Field. So once i select that ticket there should be link to be created and also de-link.

6 answers

1 accepted

0 votes
Answer accepted
Nic Brough -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.
July 21, 2013

Could you clarify the question a little?

Do you simply want to create links between issues with groovy? If so, where are you doing it? A post function?

What has the "query custom issue field" got to do with these links? From what I've seen, the plugin doesn't the have anything to do with issue links, although it duplicates some of the functionality.

0 votes
AKASHB July 22, 2013

but this is not what i am looking for.

Can we create link like:

linkManager.createIssueLink(opt.getStatusObject().getId(),issue.getStatusObject().getId(),issueLinkTypeManager.getIssueLink(issue.id),1 , currentUser)

but in my case i dont know from where to get all the parameter values?

So any help?

0 votes
Onkar Ahire
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.
July 21, 2013

JIRA:Automatically Linking Issues with a Script During Create Transition

We want to follow which issues found in which test and review sessions. In order to do this we have defined 2 new issue types called “Review Task” and “Test Task”. We have also defined a new relation called “found in”. As a improvement we also do not want to manually link issues found during a test or review to its parent task. To make the process a little bit strait forward we have added a new custom field called “Parent Task ID” to our bug issue type. While creating a bug we just enter the parent task id to this field and a workflow post function automatically links two issues with each other. Also we check validly of parent task id field with another workflow validation script. The only problem is we do not have autocomplete for parent issue id field. Any improvement is welcome.

  • First of all you should install Script Runner plugin. This plugin allows you to customise your workflows with groovy scripts without writing a whole custom plugins.
  • Define a parent issue type and customise it in the way you want. We use Review Task and Test Task issue types.
  • Define a custom field named “Parent Task ID” and add it to every other issue type that you want to automatically associate with a parent issue type (the ones you have defined above).
  • For the Create transition of workflow add following validator to validate correctness of entered “Parent Task ID” field.
    def parentTaskID = cfValues['Parent Task ID']; if (parentTaskID == null || parentTaskID == '') { return true; } else { def parentIssue = ComponentAccessor.getIssueManager(). getIssueObject(parentTaskID); def isValid = parentIssue != null && parentIssue.projectObject.key == issue.projectObject.key && (parentIssue.issueObject.name == 'Review Task' || parentIssue.issueObject.name == 'Test Task'); return isValid; }

  • Create a linkIssues.groovy file with below scrip content and put it to home folder of your JIRA installation. For the default installation on windows it is the bin folder. After that add script post function to invoke linkIssues.groovy file for Create transition. As you see in the last screen shoot this step should come after “Create the issue originally” step otherwise you will not have an issue id for linking.
    def ComponentManager componentManager = ComponentManager.getInstance(); def customFieldManager = componentManager.getCustomFieldManager(); def parentTaskIDCF = customFieldManager. getCustomFieldObject('customfield_10517');//write your own custom field id here 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 && (parentIssue.issueObject.name == 'Review Task' || parentIssue.issueObject.name == 'Test Task'); if (isParentIssueValid) { def issueLinkManager = ComponentAccessor.getIssueLinkManager(); def issueLinkTypeManager = componentManager. getComponentInstanceOfType(IssueLinkTypeManager.class); def issueLinkType = issueLinkTypeManager. getIssueLinkTypesByName('Found In').get(0); def authenticationContext = componentManager. getComponentInstanceOfType(JiraAuthenticationContext.class); issueLinkManager.createIssueLink( issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.user); } }

fdfafa

Onkar Ahire
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.
July 21, 2013

I am able to open the link and thier contains shown above.

Cheers

Onkar Ahire

0 votes
AKASHB July 21, 2013
I have tried opening this link but its not working.
0 votes
Onkar Ahire
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.
July 21, 2013

Hi Akash,

I found something which you are looking for.

http://www.denizoguz.com/2013/06/29/jiraautomatically-linking-issues-with-a-script-during-create-transition/

Regards

Onkar Ahire

0 votes
AKASHB July 21, 2013
Yes i want to create a link between 2 issues, i have grabbed there value.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events