Creating Issue Link

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 vote

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.

Yes i want to create a link between 2 issues, i have grabbed there value.
I have tried opening this link but its not working.

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

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

Cheers

Onkar Ahire

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?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Hipchat

Moving from Hipchat to Stride? Here’s what you’ll love

Heya, Hipchat friends! We’re so happy you’re checking out   Stride. Whether you know it or not, you have been instrumental in making Stride come to life. Every feature, design, and functionality...

61 views 2 6
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