Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

use scriptrunner to link issues that have the same version

Eric Sebian
Contributor
August 2, 2020

Is it possible to use Scriptrunner to use a jql search to find all issues with the same fix version of the "parent" and link those issues to said parent? 

1 answer

0 votes
Martin Bayer [MoroSystems, s.r.o.]
Community Champion
August 2, 2020

Yes, you can do almost everything with groovy scripts. When do you want to do this "linking"? Manually and just once to init your data? Or when you're updating fix version on some issue?

Eric Sebian
Contributor
August 3, 2020

I'm looking to have it linked to the primary issue whenever an issue from a specific project has that fix version added to one of its issues. I'm assuming that I'd use a listener? Maybe incorporating jql somehow?

Martin Bayer [MoroSystems, s.r.o.]
Community Champion
August 4, 2020

Yes, exactly, you will use listener which reacts to ISSUE_UPDATED. Then you need to write script which will

  1. write custom listener (I just discussed listeners here: https://community.atlassian.com/t5/Jira-questions/Custom-listener-is-showing-anything-in-logs-when-executed/qaq-p/1446145)
  2. get parent issue
  3. read parent issue's fix versions (it is collection of versions)
    1. parentIssue.getFixVersions()
  4. execute JQL "fixVersion in (parent issue's fix versions)
    1. UserManager userManager = ComponentAccessor.getUserManager()
      SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
      IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()


      Collection<Version> parentIssueVersions = parentIssue.getFixVersions()
      String parentIssueVersionsAsString = parentIssue.getFixVersions().collect{ it.getName() }.join(",")
      String jqlSearch = 'fixVersion in (' + parentIssueVersionsAsString + ')'

      def serviceUser = userManager.getUserByName("service") // you need some user which has permission to search and view issues

      //setup search
      def parseResult = searchService.parseQuery(serviceUser, jqlSearch)
      def issuesWithFixVersion = []
      if (parseResult.isValid()) {
      def searchResult = searchService.search(serviceUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
      issuesWithFixVersion = searchResult.issues
      }
  5. link found issues with parent
    1. Long linkTypeId = 1L // you need link type id

      issuesWithFixVersion.each { issueLinkManager.createIssueLink(parentIssue.id, it.id, linkTypeId, Long.valueOf(1), serviceUser ) }

       

These are just snippets of code but I hope it will help you. Feel free to post more questions here, of course.

Maybe my question... what do you mean by "parent" issue? Is it special type of issue linked to other issue with specific link type?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events