How to get a indirectly linked issue

Hi all,

so I'm very new to Jira Groovy and I have following problem:

In my JIRA project I have Services which are implemented by Features which are implemented by Feature Increments. So I want to create a scripted field which shows the summary of the Service the Issue belongs to and I came up with he following code:



    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.link.IssueLinkManager
    import com.atlassian.jira.bc.project.component.ProjectComponent
    import com.atlassian.jira.issue.Issue

    //The current user is needed as a parameter in some functions.
    def authenticationContext=ComponentAccessor.getJiraAuthenticationContext()
    def user=authenticationContext.getLoggedInUser()
    def linkManager = ComponentAccessor.getIssueLinkManager()

    //Get all issues that are linked via "implements".
    def linkedOfType =     linkManager.getLinkCollection(issue,user).getOutwardIssues("Implements")

    //When the issue implements something.
    for(issue in linkedOfType){
    
        //If the linked issue is a feature get this feature and search its     linked issues for service and return the summary of this service.
        if (issue.getIssueType().getName().toString().equals("Feature_Tile")){
       
          }    
    
        //If the linked issue is a service return the summary of this service.    
        if (issue.getIssueType().getName().toString().equals("Service")){
           String serviceName = issue.summary
           return serviceName
        }
    } 


The problem is now, that the field works fine if the issue implements a Service, but not if the issue implements a Feature, because I don't know how to get the linked Issues of this feature to search them for Services.
So my Question is: how can I get the Service if my issue only implements a Feature?

1 answer

This widget could not be displayed.
Micky Caritte Community Champion Dec 07, 2017

Hi Tina,

I think you should re-use your code from the Feature level to the service level,  something like:

...
//
If the linked issue is a feature get this feature and search its     linked issues for service and return the summary of this service.
        if (issue.getIssueType().getName().toString().equals("Feature_Tile")){
        def linkedService = linkManager.getLinkCollection(issue,user).getOutwardIssues("Implements")
for(iss in linkedService){
if (iss.getIssueType().getName().toString().equals("Service")){
return iss.summary
}
}
          }    
...

Let us know if it works!

Cheers

Hi Micky,

thanks for your answer!

I think that would probably work fine, but I already managed to solve my problem, by rewriting my code and using a while loop with a switch in it.

Micky Caritte Community Champion Dec 11, 2017

Great!

Have a great day.

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 Wednesday 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...

281 views 5 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